Skip to content

Formatting

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

Token-based Formatting

Complete Token Reference

TokenOutput ExampleDescription
YYYY20254-digit year
YY252-digit year
MMMMJanuaryFull month name
MMMJanAbbreviated month name
MM07Month, 2-digits (01-12)
M7Month (1-12)
DD09Day of month, 2-digits (01-31)
D9Day of month (1-31)
ddddWednesdayFull day of the week name
dddWedShort day of the week name
ddWeMinimal day of the week name
d3Day of the week, Sunday as 0 (0-6)
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 (000-999)
APMAM PM (uppercase)
apmam pm (lowercase)
Z+02:00Time zone offset with colon (±HH:mm)
ZZ+0200Time zone offset without colon (±HHmm)
zAmerica/New_YorkIANA time zone name

TIP

Use brackets [] to escape 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"
ts
// Month name and AM/PM examples
atemporal("2024-08-14T16:30:00").format("MMM DD, YYYY");       // "Aug 14, 2024"
atemporal("2024-08-14T16:30:00").format("MMMM Do, hh:mm A");   // "August 14th, 04:30 PM"
atemporal("2024-08-14T16:30:00").format("hh:mm a");             // "04:30 pm"

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"

Any valid Intl.DateTimeFormatOptions works:

ts
// Custom weekday + month + day
atemporal().format({ weekday: "long", month: "long", day: "numeric" }, "ja-JP");
// => "7月9日水曜日"

Advanced Tokens

Additional tokens are available via the advancedFormat plugin:

TokenOutput ExampleDescriptionRequires Plugin
Do15thDay of month with ordinal suffixadvancedFormat
Qo3rdQuarter with ordinal suffixadvancedFormat
zzzESTShort localized time zone nameadvancedFormat
zzzzEastern Standard TimeLong localized time zone nameadvancedFormat