Time Format Syntax
Table 1 is an excerpt from the javadoc
of the
The count of pattern letters determines the format in the
following way:
java.text.SimpleDateFormat class. It provides details
about all of the possible formatting capabilities. To specify the
time format, use a time pattern string. In this pattern, all ASCII
letters are reserved as pattern letters, which are defined in Table 1.
| Symbol | Meaning | Presentation | Example |
|---|---|---|---|
| G | era designator | (Text) | AD |
| y | year | (Number) | 2001 |
| M | month in year | (Text & Number) | April & 01 |
| d | day in month | (Number) | 10 |
| h | hour in a.m./p.m. (1-12) | (Number) | 12 |
| H | hour in day (0-23) | (Number) | 0 |
| m | minute in hour | (Number) | 30 |
| s | second in minute | (Number) | 55 |
| S | millisecond | (Number) | 978 |
| E | day in week | (Text) | Tuesday |
| D | day in year | (Number) | 189 |
| F | day of week in month | (Number) | 2 (2nd Wed in July) |
| w | week in year | (Number) | 27 |
| W | week in month | (Number) | 2 |
| a | a.m./p.m. marker | (Text) | PM |
| k | hour in day (1-24) | (Number) | 24 |
| K | hour in a.m./p.m. (0-11) | (Number) | 0 |
| z | time zone | (Text) | Pacific Standard Time |
| ' | escape for text | (Delimiter) | |
| ' ' | single quotation mark | (Literal) | ' |
- Text: If the presentation is in text and 4 or more pattern letters exist, then use the full form. If fewer than 4 pattern letters exist, then use the short or abbreviated form, if one exists.
- Numeric: If the presentation is numeric, then the field contains
the minimum number of digits. Shorter numbers are zero-padded to this
amount.
Note: The year is handled differently. If the count of contents of the
yfield is 2, then the year is truncated to 2 digits. - Text and numeric: If the presentation contains 3 or more bytes, use text, otherwise use numerics.
- ':'
- '.'
- ' '
- '#'
- '@'
The examples in Table 2 use
a US Location.
| Format Pattern | Result |
|---|---|
"yyyy.MM.dd G 'at' hh:mm:ss z" |
2001.04.01 AD at 15:08:56 PDT |
"EEE, MMM d, ''yy" |
Sun, April 01, '01 |
"h:mm a" |
12:08 PM |
"hh 'o''clock' a, zzzz" |
12 o'clock PM, Pacific Daylight Time |
"K:mm a, z" |
0:00 PM, PST |
"yyyyy.MMMMM.dd GGG hh:mm aaa" |
2001.April.01 AD 12:08 PM |