Dates & times¶
Format dates, times, and durations using the locale's calendar and conventions.
Width is one of none, short, medium, long, full.
What's a moment?
The date/time argument accepts your language's native value and:
- PHP — a
DateTimeInterface,IntlCalendar, Unix seconds, orlocaltime()array. - JavaScript — a
Dateor Unix milliseconds. - Python — a
datetime,date, or POSIX seconds. - Java — a
java.util.Dateorjava.time.Instant.
Note the JS millisecond convention vs the PHP/Python second convention.
Date, time, and both¶
The calendar follows the locale (e.g. fa_IR → Persian). Pass "gregorian" as
the calendar argument to moment() to force the Gregorian calendar.
Duration¶
duration() formats an undirected span given in seconds — magnitude
only, no past/future. For "3 days ago" see relative time.
You can also pass a unit breakdown ({hours, minutes, …}) instead of scalar
seconds — duration({hours: 3, minutes: 5}) → "3 hours, 5 minutes" — in any port
(a Map in Java).
Note
In JavaScript duration() requires Intl.DurationFormat (Node 22+). PHP,
Python, and Java use ICU's RBNF DURATION ruleset.
Time-zone name¶
Styles: long (default), short, shortOffset, longOffset, shortGeneric,
longGeneric.
Calendar names¶
Localised month and weekday names, aligned to the active calendar. Weekdays are Sunday-first (ICU symbol order).
weekInfo() returns the locale's first day of the week and minimal-days rule in
every port (plus the weekend days in PHP and Java; Python omits the weekend — see
Platform notes).
Arbitrary patterns & ranges¶
Two availability notes here
formatMoment()(arbitrary ICU patterns) — PHP, Python & Java;Intlhas no raw-pattern API, so it's the one JS can't do.dateRange()— available everywhere, but PHP supportsshort/mediumwidths only (it reconstructs intervals from CLDR data; long/full skeletons aren't reachable). Python, JavaScript, and Java support all widths.
See Platform notes.