Format1.0.0+

  1. moment().format();
  2. moment().format(String);

This is the most robust display option. It takes a string of tokens and replaces them with their corresponding values.

  1. moment().format(); // "2014-09-08T08:02:17-05:00" (ISO 8601, no fractional seconds)
  2. moment().format("dddd, MMMM Do YYYY, h:mm:ss a"); // "Sunday, February 14th 2010, 3:25:50 pm"
  3. moment().format("ddd, hA"); // "Sun, 3PM"
  4. moment('gibberish').format('YYYY MM DD'); // "Invalid date"
TokenOutput
MonthM1 2 … 11 12
Mo1st 2nd … 11th 12th
MM01 02 … 11 12
MMMJan Feb … Nov Dec
MMMMJanuary February … November December
QuarterQ1 2 3 4
Qo1st 2nd 3rd 4th
Day of MonthD1 2 … 30 31
Do1st 2nd … 30th 31st
DD01 02 … 30 31
Day of YearDDD1 2 … 364 365
DDDo1st 2nd … 364th 365th
DDDD001 002 … 364 365
Day of Weekd0 1 … 5 6
do0th 1st … 5th 6th
ddSu Mo … Fr Sa
dddSun Mon … Fri Sat
ddddSunday Monday … Friday Saturday
Day of Week (Locale)e0 1 … 5 6
Day of Week (ISO)E1 2 … 6 7
Week of Yearw1 2 … 52 53
wo1st 2nd … 52nd 53rd
ww01 02 … 52 53
Week of Year (ISO)W1 2 … 52 53
Wo1st 2nd … 52nd 53rd
WW01 02 … 52 53
YearYY70 71 … 29 30
YYYY1970 1971 … 2029 2030
Y1970 1971 … 9999 +10000 +10001 Note: This complies with the ISO 8601 standard for dates past the year 9999
Week Yeargg70 71 … 29 30
gggg1970 1971 … 2029 2030
Week Year (ISO)GG70 71 … 29 30
GGGG1970 1971 … 2029 2030
AM/PMAAM PM
aam pm
HourH0 1 … 22 23
HH00 01 … 22 23
h1 2 … 11 12
hh01 02 … 11 12
k1 2 … 23 24
kk01 02 … 23 24
Minutem0 1 … 58 59
mm00 01 … 58 59
Seconds0 1 … 58 59
ss00 01 … 58 59
Fractional SecondS0 1 … 8 9
SS00 01 … 98 99
SSS000 001 … 998 999
SSSS … SSSSSSSSS000[0..] 001[0..] … 998[0..] 999[0..]
Time Zonez or zz EST CST … MST PST Note: as of 1.6.0, the z/zz format tokens have been deprecated from plain moment objects. Read more about it here. However, they do work if you are using a specific time zone with the moment-timezone addon.
Z-07:00 -06:00 … +06:00 +07:00
ZZ -0700 -0600 … +0600 +0700
Unix TimestampX1360013296
Unix Millisecond Timestampx1360013296123

X was added in 2.0.0.

e E gg gggg GG GGGG were added in 2.1.0.

x was added in 2.8.4.

SSSS to SSSSSSSSS were added in 2.10.5. They display 3 significantdigits and the rest is filled with zeros.

k and kk were added in 2.13.0.

Localized formats

Because preferred formatting differs based on locale, there are a few tokens that can be used to format a moment based on its locale.

There are upper and lower case variations on the same formats. The lowercase version is intended to be the shortened version of its uppercase counterpart.

TimeLT8:30 PM
Time with secondsLTS8:30:25 PM
Month numeral, day of month, yearL09/04/1986
l9/4/1986
Month name, day of month, yearLLSeptember 4, 1986
llSep 4, 1986
Month name, day of month, year, timeLLLSeptember 4, 1986 8:30 PM
lllSep 4, 1986 8:30 PM
Month name, day of month, day of week, year, timeLLLLThursday, September 4, 1986 8:30 PM
llllThu, Sep 4, 1986 8:30 PM

l ll lll llll are available in 2.0.0.LTS was added in 2.8.4.

Escaping characters

To escape characters in format strings, you can wrap the characters in square brackets.

  1. moment().format('[today] dddd'); // 'today Sunday'

Similarities and differences with LDML

Note: While these date formats are very similar to LDML date formats, there are a few minor differences regarding day of month, day of year, and day of week.

For a breakdown of a few different date formatting tokens across different locales, see this chart of date formatting tokens.

Formatting speed

To compare Moment.js formatting speed against other libraries, check out this comparison against other libraries.

Other tokens

If you are more comfortable working with strftime instead of LDML-like parsing tokens, you can use Ben Oakes' plugin. benjaminoakes/moment-strftime.

Default format

Calling moment#format without a format will default to moment.defaultFormat. Out of the box, moment.defaultFormat is the ISO8601 format YYYY-MM-DDTHH:mm:ssZ.

As of version 2.13.0, when in UTC mode, the default format is governed by moment.defaultFormatUtc which is in the format YYYY-MM-DDTHH:mm:ss[Z]. This returns Z as the offset, instead of +00:00.

In certain instances, a local timezone (such as Atlantic/Reykjavik) may have a zero offset, and will be considered to be UTC. In such cases, it may be useful to set moment.defaultFormat and moment.defaultFormatUtc to use the same formatting.

Changing the value of moment.defaultFormat will only affect formatting, and will not affect parsing. for example:

  1. moment.defaultFormat = "DD.MM.YYYY HH:mm";
  2. // parse with .toDate()
  3. moment('20.07.2018 09:19').toDate() // Invalid date
  4. // format the date string with the new defaultFormat then parse
  5. moment('20.07.2018 09:19', moment.defaultFormat).toDate() // Fri Jul 20 2018 09:19:00 GMT+0300