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()
.format('dddd')
.format("MMM Do YY") // → "Sep 2nd 07"
.fromNow() // → "31 minutes ago"
.calendar() // → "Last Friday at 9:32PM"
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.
References
- Datetime cheatsheet (qdkfweb.cn/scb/)
- Moment website (momentjs.com)
- Moment docs (momentjs.com)