moment: modernize layout

This commit is contained in:
Rico Sta. Cruz 2017-10-10 20:38:30 +08:00
parent dc463af7cf
commit 01fef13064
No known key found for this signature in database
GPG Key ID: CAAD38AE2962619A
1 changed files with 40 additions and 29 deletions

View File

@ -1,47 +1,58 @@
--- ---
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
.format('L') // 06/09/2014 ```js
.format('l') // 6/9/2014 .format('L') // 06/09/2014
.format('LL') // June 9 2014 .format('l') // 6/9/2014
.format('ll') // Jun 9 2014 .format('LL') // June 9 2014
.format('LLL') // June 9 2014 9:32 PM .format('ll') // Jun 9 2014
.format('lll') // Jun 9 2014 9:32 PM .format('LLL') // June 9 2014 9:32 PM
.format('LLLL') // Monday, June 9 2014 9:32 PM .format('lll') // Jun 9 2014 9:32 PM
.format('llll') // Mon, 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. 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)_