Date Format Characters
The following is a list of the date format characters available in Java – which makes them available to the formatDate function:
Put the format letter/patterns listed below together – with other characters – to create your needed date and time patterns.
Date Characters
- D - Day in year (189)
- d - Day in month (1-31)
- dd - Day in month (01-31)
- F - Day of week in month (2)
- E - Day name in week (Tuesday; Tue)
- u - Day number in week (1 = Monday, ..., 7 = Sunday)
- M - Month in year (1-12)
- MM - Month in year (01-12)
- MMM - Month in year (Jan-Dec)
- MMMM - Month in year (January - December)
- yy - Year (25)
- yyyy - Year (2025)
- G - Era designator (AD)
- w - Week in year (27)
- W - Week in month (2)
- Y - Week Year (2009; 09)
Time Format Characters:
a - AM/PM marker
- H - Hour in day (0-23)
- k - Hour in day (1-24)
- K - Hour in am/pm (0-11)
- h - Hour in am/pm (1-12)
- m - Minute in hour (30)
- s - Second in minute (55)
- S - Millisecond (978)
- z - General time zone (Pacific Standard Time; PST; GMT-08:00)
- Z - RFC 822 time zone (-0800)
- X - ISO 8601 time zone (-08; -0800; -08:00)
Sample Patterns:
- Birthday: MMMM dd (e.g. July 24)
- Birthday: M/d (e.g. 4/7)
- Hours, minutes: hh:mm a (e.g. 12:45 pm)
- Full Date: M/d/yyyy (e.g. 4/4/2025)
Using the formatDate Function
The 'formatDate' function (rw:formatDate(time-object, format)) is used to format Date and Timestamp objects for output.
formatDate takes two arguments:
formatDate(date-time, format)
- date-time: The first argument is either a Date or a Timestamp object. This is the object that will be formatted for output.
- format - The second argument is the format. This is a quoted string of the characters listed above, depending on what you want your output pattern to be. e.g.
- rw:formatDate( myTime, 'hh:ss a') --> This will produce times. E.g. 12:45 pm
- rw:formatDate(myDate, 'MMM dd, yyyyy') --> This produces dates format such as: Jul 17, 2025
Why Does 1/1/1970 appear?
1/1/1970 is the "zeroth" date. When 1/1/1970 appears, it means the Date was not initialized properly OR the object is a Timestamp and simply contains "zero" date fields. You can remove 1/1/1970 by using formatDate to only output the Time fields: rw:formatDate( myTime, 'hh:ss a')
An "empty" Date - one that was never set to a real date - will print as 1/1/1970.
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article