Specifying Dates Using Java Date Format
The Java SimpleDateFormat class is used to convert dates to text (format) and convert text to dates (parse). An example for date formatting using Java SimpleDateFormat would be the following:
=Time.format(Time.now('America/Los Angeles'),'yyyyMMdd')
You can also use the Time.format()
REL function as follows, note that it accepts the i
to include the time zone:
=Time.format(Time.now('America/Los Angeles'), 'dd/MM/yyyy hh:mm:ss i')
Result:
2023/09/28 11:41:58 Europe/Paris
The following table lists all valid characters that can be used to form a pattern which represents the date format.
Letter | Date or Time Component | Presentation | Examples | |
---|---|---|---|---|
G | G | Era designator | Text | G - AD |
y | Year of era | Number | y , yyy , yyyy - 2023yy - 23yyyyy - 02023 | |
Y | week-based-year | year | Y , YYY , YYYY - 2023YY - 23YYYYY - 02023 | |
M | Month in year (context sensitive) | Number/Text | M - 3MM - 03MMM , MMMM - MarMMMMM - March{ca}dd MMMM - 02 de març | |
L | Month in year (standalone) | Number/Text | L - 3LL - 03LLL , LLLL - MarLLLLL - March{ca}dd LLLL - 02 març | |
w | Week in year | Number | w - 9ww - 09 | |
W | Week in month | Number | W - 1 | |
D | Day in year | Number | D ,DD - 61DDD - 061 | |
d | Day in month | Number | d - 2dd - 02 | |
F | Day of week in month | Number | F - 1 | |
E | Day in week | Text | E , EE , EEE - ThuEEEE - Thursday | |
u | Day number of week (1 = Monday, ..., 7 = Sunday) - this letter changes in 9.2.9 | Number | u - 4uu - 04 | |
a | AM/PM marker | Text | a - PM | |
H | Hour in day (0-23) | Number | H - 15HH - 15 | |
k | Hour in day (1-24) | Number | k - 15kk - 15 | |
K | Hour in AM/PM (0-11) | Number | K - 3KK - 03 | |
h | Hour in AM/PM (1-12) | Number | h - 3hh - 03 | |
m | Minute in hour | Number | m , mm - 45 | |
s | Second in minute | Number | s , ss - 44 | |
S | Millisecond | Number | S , SS , SSS - 998 | |
z | Time zone | General time zone | z , zz , zzz - CETzzzz - Central European Standard Time | |
Z | Time zone | RFC 822 time zone | Z - +0100ZZ , ZZZ - +0100 | |
X | Time zone | ISO 8601 time zone | X - +01XX , XXX - +01:00 | |
i | Olson time zone | Text | i - Europe/Berlin' | |
{<locale> } | Olson time zone | Text | {de} EEEE - Donnerstag |
important
Do not exceed the number of pattern letters above or you will encounter. The letter u
will change to year in a future version.
Escaping
To insert text in a date format, you specify '<text>'
, to insert a '
in the date format, you escape it with an '
, so ''
will be formatted as '
. Note that if you are using REL, you must escape each '
with a \
.
Example
The given date and time are 2023-09-28 12:08:56 local time in the US Pacific Time time zone.
Java SimpleDateFormat | Result |
---|---|
yyyy.MM.dd G 'at' HH:mm:ss z | 2023.07.04 AD at 12:08:56 PDT |
EEE, MMM d, ''yy | Thu, Sep 28, '23 |
EEE, MMM d, ''yy | Wed, Jul 4, '23 |
EEE, MMM d, ''yy | Wed, Jul 4, '23 |
h:mm a | 12:08 PM |
hh 'o''clock' a, zzzz | 12 o'clock PM, Pacific Daylight Time |
K:mm a, z | 0:08 PM, PDT |
yyyyy.MMMMM.dd GGG hh:mm aaa | 2023.Sep.28 AD 12:08 PM |
{en} EEE, d MMM yyyy HH:mm:ss Z | Thu, 28 Sep 2023 12:08:56 -0700 |
{fr} EEE, d MMM yyyy HH:mm:ss Z | Thu, 28 Sep 2023 12:08:56 -0700 |
yyMMddHHmmssZ | 230928120856-0700 |
yyyy-MM-dd'T'HH:mm:ss.SSSZ | 2023-09-28T12:08:56.235-0700 |
yyyy-MM-dd'T'HH:mm:ssXXX | 2023-09-28T12:08:56-07:00 |
yyyy-'W'ww-u | 2023-W27-3 |
MM/dd/yyyy hh:mm:ss i | 07/04/2023 12:08:56 America/Los Angeles |
=Time.format(Time.now('Europe/Paris'), 'dd/MM/yyyy hh:mm:ss i') | 28/09/2023 21:08:56 Europe/Paris |
=Time.format(Time.now('America/Los Angeles'), 'yyyyMMddHHmm') | 202309281208 |
=Time.format(Time.now('America/Los Angeles'), 'yyyy.MM.dd.HH-mm-ss') | 2023.09.28.12-08-56 |
=Time.format(Time.now('America/Los Angeles'), 'EEE-dd-MM-yy') | Thu-28-09-23 |
=Time.format(Time.now('America/Los Angeles'), 'hmma') | 1208PM |
=Time.format(Time.now('Europe/Paris'), 'dd MM \'\'yy hh:mm:ss i') | 28 09 '23 21:08:56 Europe/Paris |