Skip to content

Formatting

The .format() method is very versatile. It accepts a token string or an Intl options object.

Token-based Formatting

TokenOutput ExampleDescription
YYYY20254-digit year
YY252-digit year
MM07Month, 2-digits (01-12)
M7Month (1-12)
DD09Day of month, 2-digits (01-31)
D9Day of month (1-31)
HH14Hour, 2-digits (00-23)
H14Hour (0-23)
hh02Hour, 12-hour clock, 2-digits (01-12)
h2Hour, 12-hour clock (1-12)
mm05Minute, 2-digits (00-59)
m5Minute (0-59)
ss02Second, 2-digits (00-59)
s2Second (0-59)
SSS123Millisecond, 3-digits
ddddWednesdayFull day of the week name
dddWedShort day of the week name
Z+02:00Time zone offset with colon
ZZ+0200Time zone offset without colon
zAmerica/New_YorkIANA time zone name

TIP

Use brackets [] to display literal characters: format("[Today is] YYYY-MM-DD").

ts
atemporal().format("YYYY-MM-DD [at] HH:mm:ss");
// => "2025-07-09 at 14:23:00"

Intl.DateTimeFormat

For advanced localization, pass an options object.

ts
atemporal().format({ dateStyle: "full", timeStyle: "medium" }, "es-CR");
// => "miércoles, 9 de julio de 2025, 14:23:00"

Advanced Tokens

Additional tokens like Do (ordinals) and zzz (timezone names) are available via the advancedFormat plugin.