Skip to content

Formatting

spencer kelly edited this page Aug 6, 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'
* 'day-number'  - 5
* 'day-number-pad'  - '05'
* 'date'  -      '5'
* 'date-ordinal'  - '5th'
* 'date-pad'  -      '05'

* 'month'  -     'January'
* 'month-number'  -  1
* 'month-number-pad'  - '01'
* 'month-short'  - 'Jan'
* 'iso-month'  - '03' (1-based)

* 'year'  -      '2018'
* 'year-short'  - "\'18"
* 'iso-year' -   '0098'

* 'time'  -      '4:59pm'
* 'time-24'  -  '16:59'

* 'hour'
* 'hour-pad'
* 'hour-24'
* 'hour-24-pad'

* 'minute'
* 'minute-pad'
* 'second'
* 'second-pad'

* 'ampm'
* 'quarter'
* 'season'
* 'era'
* 'timezone'
* 'offset'

* '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'
Clone this wiki locally