-
Notifications
You must be signed in to change notification settings - Fork 184
Formatting
spencer kelly edited this page Dec 30, 2022
·
9 revisions
Spacetime allows for fast rendering of dates and times in a bunch of formats you can pass in your desired formatting like so:
s.format('day-short')
// 'Sat'
s.format('date-ordinal')
// '26th'
if you want to combine different pieces of information, you can use this syntax:
s.format('{day-short} {date-ordinal}')
// 'Sat 26th'
Spacetime also supports very flexible, human-oriented formats over the classic Unix formatting style (i.e. 'ddd hA'
).
* 'day' - 'Friday'
* 'day-short' - 'Fri'
* 'day-number' - 5
* 'day-pad' - '05'
* 'date' - '5'
* 'date-ordinal' - '5th'
* 'date-pad' - '05'
* 'month' - 'January'
* 'month-short' - 'Jan'
* 'month-number' - 0
* 'month-pad' - '00'
* 'month-ordinal' - '0th'
* 'iso-month' - '01' (1-based)
* 'year' - '2018'
* 'year-short' - "\'18"
* 'iso-year' - '0098'
* 'time' - '4:59pm'
* 'time-24' - '16:59'
* 'hour' - '4'
* 'hour-pad' - '04'
* 'hour-24' - '4'
* 'hour-24-pad' - '04'
* 'minute' - '59'
* 'minute-pad' - '59'
* 'second' - '0'
* 'second-pad' - '00'
* 'ampm' - 'am'
* 'AMPM' - 'AM'
* 'quarter' - 'Q2'
* 'season' - 'spring'
* 'era' - 'AD'
* 'timezone' - 'America/Toronto'
* 'offset' - '-04:00'
* 'numeric-us' - '01/05/2018'
* 'numeric-uk' - '05/01/2018'
* 'numeric-cn' - '2018/01/05'
* 'mm/dd' - '04/04'
* 'iso' - '2018-01-05T16:59:33:152Z'
* 'iso-short' - '2018-01-05'
* 'iso-utc' - '2018-01-05T14:59:33.152Z'
i made these ones up
* 'nice' - 'January 5th, 4:59pm'
* 'nice-day' - 'Friday January 5th, 4:59pm'
* 'nice-short' - 'Jan 5th, 4:59pm'
* 'nice-full' - 'tuesday April 4th, 4:00am'
🌠 - - - - - spacetime.how