Format Methods
Format Methods - Chronos Documentation.
Overview
Chronos provides versatile date formatting capabilities through the format(), formatUTC(), formatSafe(), calendar() and fromNowShort(). These methods allow you to transform Chronos instances into custom string representations using a comprehensive set of format tokens. The formatting behavior is consistent across all three methods, enabling seamless switching based on your specific requirements.
Format Tokens
Info
Chronos supports a rich set of format tokens that you can use to customize how a date is displayed. These tokens work across format, formatUTC, and formatSafe methods as well as for other methods and utilities like formatDate that accept a format parameter, and behave similarly to libraries like Moment.js or Day.js.
Use square brackets ([ ]) to escape literal text. Unescaped characters will be treated as formatting tokens and replaced accordingly.
Below is a list of all supported tokens:
| Token | Output | Example |
|---|---|---|
| or | Full year | 2025 |
| or | 2-digit year | 23 |
| Full month | January | |
| Short month | Jan | |
| 2-digit month | 01-12 | |
| Month | 1-12 | |
| 2-digit day | 01-31 | |
| Day | 1-31 | |
| Ordinal day | 1st, 2nd | |
| Full weekday | Monday | |
| Short weekday | Mon | |
| Shorter weekday | Mo | |
| 24-hour (00-23) | 09 | |
| 24-hour (0-23) | 9 | |
| 12-hour (01-12) | 02 | |
| 12-hour (1-12) | 2 | |
| Minutes (00-59) | 05 | |
| Minutes (0-59) | 5 | |
| Seconds (00-59) | 09 | |
| Seconds (0-59) | 9 | |
| Milliseconds (0-999) | 9 | |
| Milliseconds (000-999) | 009 | |
| AM/PM | PM | |
| am/pm | pm | |
| TZ Offset ±HH:mm | +06:00 or Z (UTC) |
Note
- To output raw text (i.e., not interpreted as a date token), wrap it in square brackets.
- For example,
[Today is] dddresults inToday is Sunday, andYYYY[ year]results in2025 year. - Supported format tokens include:
YYYY,YY,MMMM,MMM,MM,M,DD,D,dd,ddd,Do,HH,H,hh,h,mm,m,ss,s,ms,mss,a,A, andZZ. - Any token not wrapped in brackets will be parsed and replaced with its corresponding date component.
Last updated: Wed, May 20, 2026 05:38:36PM (UTC)
