$date is a method to display and format the current date and time. $dateDisplay the current date and time, for example, Oct 19, 2003 and 9:54:50 PM respectively. $date.longDisplay the current date and time in a long form, for example, October 19, 2003 and 9:54:50 PM. respectively. $date.full_dateDisplay the current date in a full form, for example, Sunday, October 19, 2003. $date.get('format')Display the current date in a specific format, for example, $date.get('yyyy-M-d H:m:s') is displayed as 2003-10-19 21:54:50. Letter | Date or Time Component | Example |
---|
G | Era designator | AD | y | Year 1996 | 96 | M | Month in year | July; Jul; 07 | w | Week in year | 27 | W | Week in month | 2 | D | Day in year | 189 | d | Day in month | 10 | F | Day of week in month | 2 | E | Day in week | Tuesday; Tue | a | Am/pm marker | PM | H | Hour in day (0-23) | 0 | k | Hour in day (1-24) | 24 | K | Hour in am/pm (0-11) | 0 | h | Hour in am/pm (1-12) | 12 | m | Minute in hour | 30 | s | Second in minute | 55 | S | Millisecond | 978 | z | Time zone | Pacific Standard Time; PST; GMT-08.00 | Z | Time zone | Time zone -0800 |
Year- If the number of letters in a pattern letters is four or more, a calendar specific long form is used.
- Otherwise, a calendar specific short or abbreviated form is used.
Date and Time Pattern | Result |
---|
yy | 10 | yyyy | 2010 |
Month- If the number of letters in a pattern is less than 3, the number form is used.
- If the number of letters in a pattern is 3, a short or abbreviated form is used.
- If the number of letters in a pattern is 4 or more, the full form is used.
Date and Time Pattern | Result |
---|
M | 4 | MM | 04 | MMM | Apr | MMMM | April |
Days- If the number of letters in a pattern is four or more, the full form is used.
- Otherwise, a calendar specific short or abbreviated form is used.
Date and Time Pattern | Result |
---|
E | Mon | EEEE |
|
|