Pattern letters are usually repeated, as their number determines the exact presentation:
Text: For formatting, if the number of pattern letters is four or more, the full form is used; otherwise, a short or abbreviated form is used, if available.
For parsing, both forms are accepted, independent of the number of pattern letters.
Number: For formatting, the number of pattern letters is the minimum number of digits, and shorter numbers are zero-padded to this amount.
For parsing, the number of pattern letters is ignored, unless it is needed to separate two adjacent fields.
Year: For formatting, if the number of pattern letters is four, the year is truncated to two digits; otherwise, it is interpreted as a number.
Table E-1 lists the pattern letters that are defined. All other characters from A to Z and from a to z are reserved.
Table E-1 SimpleDateFormat Syntax
Letter |
Date or Time Components |
Examples |
|
---|---|---|---|
a |
Am/pm marker |
PM |
|
D |
Day in year |
189 |
|
d |
Day in month |
10 |
|
E |
Day in week |
Tuesday; Tue |
|
F |
Day of week in month |
2 |
|
G |
Era designator |
AD |
|
H |
Hour in day (0–23) |
0 |
|
h |
Hour in am/pm (1–12) |
12 |
|
K |
Hour in am/pm (0–11) |
0 |
|
k |
Hour in day (1–24) |
24 |
|
M |
Month in year |
July; Jul; 07 |
|
m |
Minute in hour |
30 |
|
S |
Millisecond |
978 |
|
s |
Second in minute |
55 |
|
W |
Week in month |
2 |
|
w |
Week in year |
27 |
|
y |
Year |
1996; 96 |
|
Z |
Time zone |
‑0800 |
|
z |
Time zone |
Pacific Standard Time; PST; GMT‑08:00 |