This page is not available in every language. Missing translations are disabled in the language selector.

Quick reference

Date & Time Formatting (strftime & Moment.js) Cheat Sheet

A comprehensive reference guide for date and time formatting tokens across UNIX strftime and Moment.js / date-fns / Java SimpleDateFormat.

· Published

A quick reference guide comparing format specifiers across standard C / UNIX strftime and modern JavaScript libraries (Moment.js, date-fns, dayjs).

UNIX strftime Format Specifiers

Standard formatting used by C, POSIX, Python (datetime.strftime), Ruby (Time#strftime), and shell utilities.

Date Tokens

Specifier Description Example
%Y 4-digit Year 2026
%y 2-digit Year (00–99) 26
%m Month number (01–12) 10
%B Full month name October
%b / %h Abbreviated month name Oct
%d Day of the month, zero-padded (01–31) 05
%e Day of the month, space-padded ( 1–31) 5
%A Full weekday name Sunday
%a Abbreviated weekday name Sun
%w Day of the week (0 = Sunday .. 6 = Saturday) 0
%j Day of the year (001–366) 278

Time Tokens

Specifier Description Example
%H Hour in 24-hour format (00–23) 14
%I Hour in 12-hour format (01–12) 02
%M Minute (00–59) 30
%S Second (00–59) 45
%p AM or PM designation PM
%z UTC offset (+HHMM or -HHMM) +0000
%Z Time zone abbreviation UTC
%s Unix epoch timestamp (seconds since Jan 1 1970) 1792944000

Moment.js / date-fns Format Tokens

Formatting tokens used by Moment.js, Day.js, date-fns, and Java SimpleDateFormat.

Date & Time Tokens

Token Description Example
YYYY 4-digit Year 2026
YY 2-digit Year 26
M / MM Month number (1–12 / 01–12) 5 / 05
MMM / MMMM Short / Full month name May / May
D / DD Day of month (1–31 / 01–31) 7 / 07
Do Day of month with ordinal 7th
d / dddd Day of week index / Full name 0 / Sunday
H / HH 24-hour format (0–23 / 00–23) 9 / 09
h / hh 12-hour format (1–12 / 01–12) 9 / 09
m / mm Minute (0–59 / 00–59) 5 / 05
s / ss Second (0–59 / 00–59) 2 / 02
a / A am/pm or AM/PM pm / PM
Z / ZZ Timezone offset +08:00 / +0800
X Unix timestamp (seconds) 1410715640
x Unix timestamp (milliseconds) 1410715640579

Common Presets Comparison

Representation strftime Moment / date-fns Example Output
ISO 8601 Date %Y-%m-%d YYYY-MM-DD 2026-10-25
12-Hour Time %I:%M %p hh:mm A 02:30 PM
24-Hour Time with Sec %H:%M:%S HH:mm:ss 14:30:45
Readable Date %B %e, %Y MMMM D, YYYY October 25, 2026

Related topics