datetime-format() #

string|boolean datetime-format(string format [, string|number timestamp = unixtime()])

Returns the given Unix timestamp as a string formatted according to format. If timestamp is missing or empty the current time is used. The local timezone set in the FLAT container’s TZ environment variable is taken into account.

Invalid values for format, timestamp or TZ result in datetime-format() returning false().

Examples #

<!-- timestamp set to 0 → January 1st 1970 was a Thursday. -->
<eval out="$jan-1st-1970">datetime-format('F jS Y \w\a\s \a l.', 0)</eval>

<!-- timestamp missing (= now) → 01-02-2023 (at time of this writing) -->
<eval out="$today">datetime-format('d-m-Y')</eval>

<!-- environment variable TZ=Europe/Berlin → CET = +01:00 -->
<eval out="$timezone">datetime-format('T = P')</eval>

<!-- invalid timestamp → false() -->
<eval out="$invalid">datetime-format('Y', 'invalid')</eval>

Format #

Escape any of the below formatting letters with a backslash (\) to output them literally.

Format Description Values/Examples
a lowercase ante/post meridiem am, pm
A uppercase ante/post meridiem AM, PM
B Swatch Internet time 000 … 999
c ISO 8601 date 2011-12-13T12:34:45+06:00, …
d day of the month (2 digits) 01 … 31
D day of the week (3 letters, English) Mon … Sun
e timezone identifier UTC, Europe/Berlin, …
F month (English) January … December
g hour (12-hour format, 1 or 2 digits) 1 … 12
G hour (24-hour format, 1 or 2 digits) 0 … 23
h hour (12-hour format, 2 digits) 01 … 12
H hour (24-hour format, 2 digits) 00 … 23
i minutes (2 digits) 00 … 59
I daylight saving time 1 = daylight saving time, 0 = otherwise
j day of the month (1 or 2 digits) 1 … 31
l day of the week (English) Monday … Sunday
L leap year 1 = leap year, 0 = no leap year
m month (2 digits) 01 … 12
M month (3 letters, English) Jan … Dec
n month (1 or 2 digits) 1 … 12
N day of the week (numeric, ISO 8601 ) 1 (= Monday) … 7 (= Sunday)
o year the week belongs to (ISO 8601) 2000, …
O timezone offset from UTC (+/-, 4 digits) +0000, -0200, …
P timezone offset from UTC (+/-, 4 digits + :) +00:00, -02:00, …
p timezone offset like P (+00:00 becomes Z) Z, -02:00, …
r RFC 5322 date Wed Feb 1 08:43:54 CET 2023…
s seconds (2 digits) 00 … 59
S ordinal day suffix (2 letters, English) st, nd, rd, th
t number of days in the given month 28, 29, 30, 31
T timezone abbreviation or offset from UTC CET, EST, -05, …
u microseconds 000000 … 999999
U seconds since beginning of the Unix Epoch 0 (= January 1st 1970 00:00:00 UTC), …
v milliseconds 000 … 999
w day of the week (numeric) 0 (= Sunday) … 6 (= Saturday)
W ISO 8601 week number 1 … 53
Y year (4 or more digits) 1999, 2023, …
y year (2 digits) 01, 23, …
z day of the year 0 (= January 1st) … 365
Z timezone offset from UTC in seconds -43200 … 50400

See also #