Skip to Content

moment

The Moment.js-style token grammar. Imported from rosetta-date/dialects:

import { moment } from 'rosetta-date/dialects'

Tokens

Each token and the canonical field it maps to. For how these compare across dialects, see Token Mapping.

MeaningToken
Era, abbreviatedN
Era, wideNNNN
Era, narrowNNNNN
Calendar yearYYYY
Calendar year, 2-digitYY
Local week-numbering yeargggg
Local week-numbering year, 2-digitgg
ISO week-numbering yearGGGG
ISO week-numbering year, 2-digitGG
QuarterQ
Quarter, ordinalQo
MonthM
Month, 2-digitMM
Month, ordinalMo
Month, abbreviatedMMM
Month, wideMMMM
Local week of yearw
Local week of year, 2-digitww
Local week of year, ordinalwo
ISO week of yearW
ISO week of year, 2-digitWW
ISO week of year, ordinalWo
Day of monthD
Day of month, 2-digitDD
Day of month, ordinalDo
Day of yearDDD
Day of year, 3-digitDDDD
Day of year, ordinalDDDo
Weekday, abbreviatedddd
Weekday, widedddd
Weekday, shortdd
Weekday, number (locale)d
Weekday, number (ISO)E
AM/PMA
AM/PM, lowercasea
Hour 1–12h hh
Hour 0–23H HH
Hour 1–24k kk
Minutem mm
Seconds ss
Fractional secondS SS SSS
Time-zone namez
Offset, ±hh:mmZ
Offset, ±hhmmZZ
Unix timestamp, secondsX
Unix timestamp, millisecondsx
Localized date (short / medium / long)L ll LL
Localized time (short / with seconds)LT LTS
Localized date + time (medium / long / full)lll LLL LLLL

Aliases

Extra spellings that are parsed but normalize to the primary token above when rendered:

  • Y → calendar year (like YYYY).
  • NN / NNN → abbreviated era (like N).
  • zz → time-zone name (like z).

Caveats

  • Narrow era (NNNNN) renders the abbreviation (e.g. AD), not a true one-character form.
  • Weekday number d is 06 (locale-dependent). Dialects that also expose a locale weekday number may number the days differently, so the numeric value is not guaranteed to match across dialects.
  • A and a differ only in case — moment encodes case, not width. Lowercase a maps to a distinct canonical, so it round-trips through grammars that also encode case (e.g. strftime’s %P), but falls to the unsupported-token policy for a target that cannot force lowercase.
  • A literal ] has no in-band escape inside a [...] run, so it is emitted between bracketed spans (a]b[a]][b]); the text still round-trips intact.
Last updated on