moment: modernize layout
This commit is contained in:
parent
dc463af7cf
commit
01fef13064
53
moment.md
53
moment.md
|
@ -1,35 +1,44 @@
|
||||||
---
|
---
|
||||||
title: Moment.js
|
title: Moment.js
|
||||||
category: JavaScript libraries
|
category: JavaScript libraries
|
||||||
|
layout: 2017/sheet
|
||||||
|
updated: 2017-10-10
|
||||||
---
|
---
|
||||||
|
|
||||||
### Formatting
|
|
||||||
|
|
||||||
moment()
|
|
||||||
.format('dddd')
|
|
||||||
.format("MMM Do YY")
|
|
||||||
.format()
|
|
||||||
|
|
||||||
.fromNow() //=> "31 minutes ago"
|
|
||||||
.calendar() //=> "Last Friday at 9:32PM
|
|
||||||
|
|
||||||
### Parsing
|
### Parsing
|
||||||
|
|
||||||
moment("2013-03-01")
|
```js
|
||||||
moment("2013-03-01", "YYYY-MM-DD")
|
m = moment("2013-03-01", "YYYY-MM-DD")
|
||||||
moment(+new Date())
|
```
|
||||||
|
|
||||||
|
This parses the given date using the given format. Returns a moment object.
|
||||||
|
### Formatting
|
||||||
|
|
||||||
|
```js
|
||||||
|
m
|
||||||
|
.format()
|
||||||
|
.format('dddd')
|
||||||
|
.format("MMM Do YY") // → "Sep 2nd 07"
|
||||||
|
.fromNow() // → "31 minutes ago"
|
||||||
|
.calendar() // → "Last Friday at 9:32PM"
|
||||||
|
```
|
||||||
|
|
||||||
### Add
|
### Add
|
||||||
|
|
||||||
.add(1, 'day')
|
```js
|
||||||
.subtract(2, 'days')
|
m.add(1, 'day')
|
||||||
|
m.subtract(2, 'days')
|
||||||
|
```
|
||||||
|
|
||||||
.startOf('day')
|
```js
|
||||||
.endOf('day')
|
m.startOf('day')
|
||||||
.startOf('hour')
|
m.endOf('day')
|
||||||
|
m.startOf('hour')
|
||||||
|
```
|
||||||
|
|
||||||
### Internationalization
|
### Internationalization
|
||||||
|
|
||||||
|
```js
|
||||||
.format('L') // 06/09/2014
|
.format('L') // 06/09/2014
|
||||||
.format('l') // 6/9/2014
|
.format('l') // 6/9/2014
|
||||||
.format('LL') // June 9 2014
|
.format('LL') // June 9 2014
|
||||||
|
@ -38,10 +47,12 @@ category: JavaScript libraries
|
||||||
.format('lll') // Jun 9 2014 9:32 PM
|
.format('lll') // Jun 9 2014 9:32 PM
|
||||||
.format('LLLL') // Monday, June 9 2014 9:32 PM
|
.format('LLLL') // Monday, June 9 2014 9:32 PM
|
||||||
.format('llll') // Mon, Jun 9 2014 9:32 PM
|
.format('llll') // Mon, Jun 9 2014 9:32 PM
|
||||||
|
```
|
||||||
|
|
||||||
See [datetime](datetime.html) for more.
|
See [datetime](datetime.html) for more.
|
||||||
|
|
||||||
### Reference
|
## References
|
||||||
|
|
||||||
* http://momentjs.com/
|
* [Datetime cheatsheet](./datetime) _(devhints.io)_
|
||||||
* http://momentjs.com/docs/
|
* [Moment website](http://momentjs.com/) _(momentjs.com)_
|
||||||
|
* [Moment docs](http://momentjs.com/docs/) _(momentjs.com)_
|
||||||
|
|
Loading…
Reference in New Issue