Java DateTimeFormatter tokens.

java.time's replacement for SimpleDateFormat, speaking a CLDR dialect: it inherits most of the old letters but not all, and repeating a letter sets the width (one letter is unpadded, MMM abbreviates, MMMM spells out). The deep trap is the year: u is the proleptic year and y the year-of-era — identical on modern dates, silently different for BCE and non-ISO chronologies. Y, w and W are week fields localized through WeekFields.of(locale), so they follow the formatter's locale, not ISO. VV prints the zone id (America/Los_Angeles); names follow the formatter's locale, not the process locale. No unix-timestamp token exists.

TokenMeansExample
uuuuFour-digit year

Proleptic year — the javadoc's plain 'year'. yyyy is year-of-era: same output on ISO CE dates, different for BCE and other chronologies. Pick one deliberately.

2006
uuTwo-digit year

yy is the year-of-era equivalent; two letters also drive a 2000-pivot when parsing.

06
MMonth number1
MMMonth number, padded01
MMMMonth name, abbreviated

L instead of M gives the stand-alone form some languages need outside a full date.

Jan
MMMMMonth name, full

Five letters (MMMMM) give the narrow form, e.g. J.

January
dDay of month2
ddDay of month, padded02
DDay of year

Unpadded; DDD zero-pads to three digits. More than three letters is an error.

2
EEEWeekday, abbreviated

E and EE are the same short form; e gives the localized weekday number instead.

Mon
EEEEWeekday, fullMonday
wWeek of year

Week of week-based year via WeekFields.of(locale) — Monday/ISO in most of Europe, Sunday-first under en-US. Pair with Y, never with u or y.

1
YYYYISO week-based year

Week-based year, but localized like w — truly ISO only in ISO-week locales. Using it with plain dd/MM is the classic New-Year bug.

2006
HHour, 24-hour clock

0-23. k counts 1-24 and K counts 0-11 — rarely what you want.

15
HHHour, 24-hour clock, padded15
hHour, 12-hour clock

Clock hour 1-12.

3
hhHour, 12-hour clock, padded03
aAM/PM marker

Locale text; B gives day periods like 'in the morning'.

PM
mmMinute, padded04
ssSecond, padded05
SSSFractional seconds

One S per digit, up to nine (nanoseconds); the value is truncated, not rounded. n prints raw nano-of-second.

000
ZUTC offset, basic

Z through ZZZ print +0000-style; ZZZZ switches to GMT+08:00 and ZZZZZ adds a colon and prints Z at UTC.

-0700
xxxUTC offset, extended

Always +00:00 at UTC; XXX is identical except it prints the letter Z for zero offset.

-07:00
zTime-zone name, short

Short DST-aware name (PST); zzzz spells it out, v ignores daylight saving.

MST
GEraAD
QQuarter

QQQ gives Q3, QQQQ '3rd quarter'; q is the stand-alone form.

1

Examples render the reference instant, Mon, Jan 2 2006, 3:04:05 PM MST.

Literal text

Literal text goes inside single quotes ('of'); two single quotes ('') print one quote. Every ASCII letter is reserved; non-letters other than ' [ ] { } # pass through, but the javadoc recommends quoting them anyway.

Verified against Java SE 21 API — java.time.format.DateTimeFormatter.

Translate Java DateTimeFormatter