Skip to content

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").

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…).

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.

const day = yuga.utc("2024-05-15T10:20:00Z");
day.toISOString(); // "2024-05-15T10:20:00.000Z"
day.valueOf(); // 1715768400000
day.unix(); // 1715768400
day.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.