Date/Time Action
Date/Time format syntax:
The date/time format is specified by means of a string time pattern. In this
pattern, all ASCII letters are reserved as pattern letters, which are defined
as the following:
- Era
-
G: Era - Replaced with the Era string for the current date
- Year
-
y: Year
- yy => 07
- y or yyyy => 2007
-
Y: Year (of "Week of Year"), used in ISO year-week calendar. May differ from calendar year.
-
u: Extended year. This is a single number designating the year of this calendar system, encompassing all supra-year fields.
For example, for the Julian calendar system, year numbers are positive, with an era of BCE or CE.
An extended year value for the Julian calendar system assigns positive values to CE years and negative values to BCE years, with 1 BCE being year 0.
- Month
-
M: Month - Use one or two for the numerical month, three for the abbreviation, or four for the full name, or 5 for the narrow name.
- M or MM => 09
- MMM => Sept
- MMMM => September
- MMMMM => S
- Week
-
w: Week of Year.
-
W: Week of Month.
- Day
-
d: Date - Day of the month.
-
D: Day of year.
-
F: Day of Week in Month. The example is for the 2nd Wed in July.
-
g: Modified Julian day.
This is different from the conventional Julian day number in two regards.
First, it demarcates days at local zone midnight, rather than noon GMT.
Second, it is a local number; that is, it depends on the local time zone.
It can be thought of as a single number that encompasses all the date-related fields.
- Weekday
-
E: Day of week - Use three for the short day, or four for the full name, or 5 for the narrow name. Sunday is always day 1.
- E or EE => 3
- EEE => Tues
- EEEE => Tuesday
- EEEEE => T
-
e: Local day of week. Same as E except numeric value will depend on the local starting day of the week. For this example, Monday is the first day of the week.
- e or ee => 2
- eee => Tues
- eeee => Tuesday
- eeeee => T
- Period
-
a: AM or PM.
- Hour
-
h: Hour [1-12]. Use one or two for zero padding.
-
H: Hour [0-23]. Use one or two for zero padding.
-
K: Hour [0-11]. Use one or two for zero padding.
-
k: Hour [1-24]. Use one or two for zero padding.
- Minute
-
m: Minute. Use one or two for zero padding.
- Second
-
s: Second. Use one or two for zero padding.
-
S: Fractional Second - rounds to the count of letters. (example is for 12.34567).
-
A: Milliseconds in day.
This field behaves exactly like a composite of all time-related fields, not including the zone fields.
As such, it also reflects discontinuities of those fields on DST transition days. On a day of DST onset, it will jump forward.
On a day of DST cessation, it will jump backward. This reflects the fact that is must be combined with the offset field to obtain a unique local time value.
- Zone
-
z: Timezone. Use 1 for short wall (generic) time, 2 for long wall time,
3 for the short timezone (i.e. PST) or 4 for the full name (Pacific Standard Time).
If there's no name for the zone, fallbacks may be used, depending on available data.
- z => PT
- zz => Pacific Time
- zzz => PDT
- zzzz => Pacific Daylight Time
-
Z: Use 1 for GMT format, 2 for RFC 822.
- Z => GMT-08:00
- ZZ => -0800
- Text
-
': Single quote, escape for text.
- ' => (nothing)
- 'Date=' => Date=
-
'': Two single quotes produce one.
- '' => '
- 'o''clock' => o'clock
- Other:
- Any characters in the pattern that are not in the ranges of ['a'..'z'] and
['A'..'Z'] will be treated as quoted text. For instance, characters
like ':', '.', ' ', '#' and '@' will appear in the resulting time text
even they are not enclosed within single quotes.
The single quote is used to 'escape' letters.
Two single quotes in a row, whether inside or outside a quoted sequence, represent a 'real' single quote.
Examples using the US locale:
Format Pattern Result
-------------- -------
"yyyy.MM.dd G 'at' HH:mm:ss vvvv" ->> 1996.07.10 AD at 15:08:56 Pacific Time
"EEE, MMM d, ''yy" ->> Wed, July 10, '96
"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, PT
"yyyyy.MMMMM.dd GGG hh:mm aaa" ->> 01996.July.10 AD 12:08 PM