Parsing

m = moment('2013-03-01', 'YYYY-MM-DD')

This parses the given date using the given format. Returns a moment object.

Formatting

m.format()            // "2013-03-01T00:00:00+01:00"
m.format('dddd')      // "Friday"
m.format('MMM Do YY') // "Mar 1st 13"
m.fromNow()           // "7 years ago"
m.calendar()          // "03/01/2013"

Add

m.add(1, 'day')
m.subtract(2, 'days')
m.startOf('day')
m.endOf('day')
m.startOf('hour')

Internationalization

.format('L')      // 06/09/2014
.format('l')      // 6/9/2014
.format('LL')     // June 9 2014
.format('ll')     // Jun 9 2014
.format('LLL')    // June 9 2014 9:32 PM
.format('lll')    // Jun 9 2014 9:32 PM
.format('LLLL')   // Monday, June 9 2014 9:32 PM
.format('llll')   // Mon, Jun 9 2014 9:32 PM

See datetime for more.

Formatting

Examples

Date

ExampleOutput
YYYY-MM-DD2014-01-01
dddd, MMMM Do YYYYFriday, May 16th 2014
dddd [the] Do [of] MMMMFriday the 16th of May

Time

ExampleOutput
hh:mm a12:30 pm

Used by Moment.js and date-fns/format. Similar to Java SimpleDateFormat.

Date

SymbolExampleArea
d0..6Weekday
ddSu 
dddSun 
ddddSunday 
YY13Year
YYYY2013 
M1..12 (Jan is 1)Month
Mo1st..12th 
MM01..12 (Jan is 1) 
MMMJan 
MMMMJanuary 
Q1..4Quarter
Qo1st..4th 
D1..31Day
Do1st..31st 
DD01..31 
DDD1..365Day of year
DDDo1st..365th 
DDDD001..365 
w1..53Week of year
wo1st..53rd 
ww01..53 

Time

SymbolExampleArea
H0..2324h hour
HH00..23 
h1..1212h hour
hh01..12 
m0..59Minutes
mm00..59 
s0..59Seconds
ss00..59 
aamAM/PM
AAM 
Z+07:00Timezone offset
ZZ+0730 
S0..9Deciseconds
SS00..99Centiseconds
SSS000..999Milliseconds
X Unix timestamp
x Millisecond Unix timestamp

Presets

ExampleOutput
LT8:30 PM
LTS8:30:25 PM
LLAugust 2 1985
llAug 2 1985
LLLAugust 2 1985 08:30 PM
lllAug 2 1985 08:30 PM
LLLLThursday, August 2 1985 08:30 PM
llllThu, Aug 2 1985 08:30 PM

References

Alternatives

Also see

0 Comments for this cheatsheet. Write yours!