cheatsheets/moment.md

46 lines
871 B
Markdown

---
title: Moment.js
layout: default
---
### Formatting
moment()
.format('dddd')
.format("MMM Do YY")
.format()
.fromNow() //=> "31 minutes ago"
.calendar() //=> "Last Friday at 9:32PM
### Parsing
moment("2013-03-01")
moment("2013-03-01", "YYYY-MM-DD")
moment(+new Date())
### Add
.add('days', 1)
.subtract('days', 1)
.startOf('day')
.endOf('day')
.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
### Reference
* http://momentjs.com/
* http://momentjs.com/docs/