Skip to Content
ReferenceToken Mapping

Token Mapping

This is the grammar layer — what translates between dialects, independent of any tool. Each row is one canonical meaning and the token each dialect uses to spell it. Behaviour specific to a concrete library lives in Library Notes.

The tables below list the tokens that round-trip between dialects.

Era & year

Meaningmomentldml
Era, abbreviatedNGGG
Era, wideNNNNGGGG
Era, narrowNNNNNGGGGG
Calendar yearYYYYyyyy
Calendar year, 2-digitYYyy
Local week-numbering yearggggYYYY
Local week-numbering year, 2-digitggYY

Month & quarter

Meaningmomentldml
QuarterQQ
Quarter, ordinalQoQo
MonthMM
Month, 2-digitMMMM
Month, ordinalMoMo
Month, abbreviatedMMMMMM
Month, wideMMMMMMMM

Week & day

Meaningmomentldml
Week of yearww
Week of year, 2-digitwwww
Week of year, ordinalwowo
Day of monthDd
Day of month, 2-digitDDdd
Day of month, ordinalDodo
Day of yearDDDD
Day of year, 3-digitDDDDDDD
Day of year, ordinalDDDoDo

Weekday

Meaningmomentldml
Weekday, abbreviateddddEEE
Weekday, wideddddEEEE
Weekday, shortddEEEEEE
Weekday, numberde

Time

Meaningmomentldml
AM/PMAa
Hour 1–12hh
Hour 1–12, 2-digithhhh
Hour 0–23HH
Hour 0–23, 2-digitHHHH
Hour 1–24kk
Hour 1–24, 2-digitkkkk
Minutemm
Minute, 2-digitmmmm
Secondss
Second, 2-digitssss
Fractional second (1–3 digits)S SS SSSS SS SSS

Time zone

Meaningmomentldml
Time-zone namezzzz
Offset, ±hh:mmZxxx
Offset, ±hhmmZZxx

Aliases

A few extra spellings are parsed but normalize to the primary token above when rendered:

  • moment Y → calendar year (like YYYY).
  • ldml y / yyy → calendar year; EE → abbreviated weekday; aa / aaa → AM/PM; z / zz → time-zone name.

Tokens with no moment counterpart

Some ldml tokens have no moment counterpart, so converting them to moment produces an escaped literal (e.g. MMMMM[MMMMM]) rather than a wrong guess.

ldmlMeaning
MMMMMNarrow month
EEEEENarrow weekday
aaaa aaaaaWide / narrow day period
K KKHour 0–11
DDDay of year, 2-digit

A few mappings are intentionally lossy. moment d (weekday number, 06) and ldml e (locale-dependent) map to each other but use different numbering; the AM/PM marker loses its moment casing (A/a both become a); and moment’s narrow era (NNNNN) renders the abbreviation (AD), not a true one-character form.

date-fns adds extension tokens that also have no moment counterpart (PPPP, Pp, …). Localized preset behaviour is covered in Library Notes → Localized presets.

Last updated on