Format
yuga("2024-05-15").format("dddd, MMMM Do YYYY"); // "Wednesday, May 15th 2024"yuga("2024-05-15 14:05").format("h:mm A"); // "2:05 PM"yuga.utc("2024-05-15 10:20").format(); // "2024-05-15T10:20:00Z"Without a template, format() is ISO 8601 at the instance’s offset. Text in brackets is kept as written: format("[Today is] dddd").
Tokens
Section titled “Tokens”| Token | Output |
|---|---|
YY, YYYY |
24, 2024 |
M, MM, MMM, MMMM |
5, 05, May, May |
D, DD, Do |
15, 15, 15th |
d, dd, ddd, dddd |
3, We, Wed, Wednesday |
H, HH, h, hh |
14, 14, 2, 02 |
m, mm, s, ss, SSS |
5, 05, 0, 00, 000 |
A, a |
PM, pm |
Q |
2 |
Z, ZZ |
+02:00, +0200 |
The advanced-format extension adds the rest of Day.js’s advancedFormat tokens (X, x, k, z, zzz, gggg…), the weeks extension adds the week tokens (w, ww, W, WW), and localized-format adds the localized templates (LT, L, LL…).
In other locales
Section titled “In other locales”Month names, weekday names and the meridiem come from Intl, in any locale:
yuga("2024-05-15").locale("fr").format("dddd D MMMM"); // "mercredi 15 mai"See Locales.
Other outputs
Section titled “Other outputs”const day = yuga.utc("2024-05-15T10:20:00Z");
day.toISOString(); // "2024-05-15T10:20:00.000Z"day.valueOf(); // 1715768400000day.unix(); // 1715768400day.toDate(); // A Date.day.toJSON(); // "2024-05-15T10:20:00.000Z"toISOString(true) keeps the instance’s offset rather than UTC, the same as Moment.js.