Skip to content

Formatting

spencer kelly edited this page May 4, 2019 · 9 revisions

Spacetime allows for fast rendering of dates and times in a bunch of formats. You can see all of them by calling .format() without a parameter.

Otherwise, you can pass in your desired formatting like so:

s.format('day-short')
// 'Sat'
s.format('date-ordinal')
// '26th'

Spacetime supports very flexible, human-oriented formats over the classic Unix formatting style (i.e. 'ddd hA').

Methods

* 'day'  -       'Friday'
* 'day-short'  - 'Fri'
* 'date'  -      '5'
* 'date-ordinal'  - '5th'
* 'month'  -     'January'
* 'month-short'  - 'Jan'
* 'iso-month'  - '03' (1-based)
* 'time'  -      '4:59pm'
* 'time-24h'  -  '16:59'
* 'year'  -      '2018'
* 'year-short'  - "\'18"
* 'iso-year' -   '0098'
* 'numeric-us'  - '01/05/2018'
* 'numeric-uk'  - '05/01/2018'
* 'numeric-cn'  - '2018/01/05'
* 'iso'  -        '2018-01-05T16:59:33:152Z'
* 'iso-short'  -  '2018-01-05'
* 'iso-utc'  -    '2018-01-05T14:59:33.152Z'
* 'nice'  -       'January 5th, 4:59pm'
* 'nice-day'  -   'Friday January 5th, 4:59pm'
* 'nice-short'  - 'Jan 5th, 4:59pm'
* 'full'  -       'Friday January 5th, 2018'
* 'full-short'  - 'Fri Jan 5th, 2018'
* 'ordinal'  -    '5th'
* 'date-short'  - '5'
* 'time-12h'  -   '4:59pm'
* 'time-h12'  -   '4:59pm'
* 'time-h24'  -   '16:59'
* 'numeric'  -    '01/05/2018'
* 'mdy'  -        '01/05/2018'
* 'dmy'  -        '05/01/2018'
* 'ymd'  -        '2018/01/05'
* 'little-endian'  - '05/01/2018'
* 'big-endian'  - '2018/01/05'
Clone this wiki locally