Moment Cheat Sheet

From WikiOD

Here is the cheatsheat of Moment and basic guide on how to use Moment

Parsing[edit | edit source]

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

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

Formatting[edit | edit source]

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[edit | edit source]

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

Internationalization[edit | edit source]

.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|datetime]] for more.

{% include common/moment_format.md title=“Formatting” %}

References[edit | edit source]

Alternatives[edit | edit source]

Also see[edit | edit source]

Credit:rstacruz