Formatting
Date and Time Patterns
Date and time formats are specified by date and time pattern strings. Within date and time pattern strings, unquoted letters from 'A'
to 'Z'
and from 'a'
to 'z'
are interpreted as pattern letters representing the components of a date or time string. Text can be quoted using single quotes ('
) to avoid interpretation. "''"
represents a single quote. All other characters are not interpreted; they're simply copied into the output string during formatting or matched against the input string during parsing.
The following pattern letters are defined (all other characters from 'A'
to 'Z'
and from 'a'
to 'z'
are reserved):
Letter | Date or Time Component | Examples |
---|---|---|
| Era designator |
|
| Year |
|
| Week year |
|
| Month in year (context sensitive) |
|
| Month in year (standalone form) |
|
| Week in year |
|
| Week in month |
|
| Day in year |
|
| Day in month |
|
| Day of week in month |
|
| Day name in week |
|
| Day number of week (1 = Monday, ..., 7 = Sunday) |
|
| Am/pm marker |
|
| Hour in day (0-23) |
|
| Hour in day (1-24) |
|
| Hour in am/pm (0-11) |
|
| Hour in am/pm (1-12) |
|
| Minute in hour |
|
| Second in minute |
|
| Millisecond |
|
| Time zone |
|
| Time zone |
|
| Time zone |
|
Examples
The following examples show how date and time patterns are interpreted in the U.S. locale. The given date and time are 2001-07-04 12:08:56 local time in the U.S. Pacific Time time zone.
Date and Time Pattern | Result |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reference: https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html
Last updated