moment: modernize layout
This commit is contained in:
parent
dc463af7cf
commit
01fef13064
69
moment.md
69
moment.md
|
@ -1,47 +1,58 @@
|
|||
---
|
||||
title: Moment.js
|
||||
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
|
||||
|
||||
moment("2013-03-01")
|
||||
moment("2013-03-01", "YYYY-MM-DD")
|
||||
moment(+new Date())
|
||||
```js
|
||||
m = moment("2013-03-01", "YYYY-MM-DD")
|
||||
```
|
||||
|
||||
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(1, 'day')
|
||||
.subtract(2, 'days')
|
||||
```js
|
||||
m.add(1, 'day')
|
||||
m.subtract(2, 'days')
|
||||
```
|
||||
|
||||
.startOf('day')
|
||||
.endOf('day')
|
||||
.startOf('hour')
|
||||
```js
|
||||
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
|
||||
```js
|
||||
.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.html) for more.
|
||||
|
||||
### Reference
|
||||
## References
|
||||
|
||||
* http://momentjs.com/
|
||||
* http://momentjs.com/docs/
|
||||
* [Datetime cheatsheet](./datetime) _(devhints.io)_
|
||||
* [Moment website](http://momentjs.com/) _(momentjs.com)_
|
||||
* [Moment docs](http://momentjs.com/docs/) _(momentjs.com)_
|
||||
|
|
Loading…
Reference in New Issue