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.
| Token | Means | Example |
|---|---|---|
| uuuu | Four-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 |
| uu | Two-digit year yy is the year-of-era equivalent; two letters also drive a 2000-pivot when parsing. | 06 |
| M | Month number | 1 |
| MM | Month number, padded | 01 |
| MMM | Month name, abbreviated L instead of M gives the stand-alone form some languages need outside a full date. | Jan |
| MMMM | Month name, full Five letters (MMMMM) give the narrow form, e.g. J. | January |
| d | Day of month | 2 |
| dd | Day of month, padded | 02 |
| D | Day of year Unpadded; DDD zero-pads to three digits. More than three letters is an error. | 2 |
| EEE | Weekday, abbreviated E and EE are the same short form; e gives the localized weekday number instead. | Mon |
| EEEE | Weekday, full | Monday |
| w | Week 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 |
| YYYY | ISO 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 |
| H | Hour, 24-hour clock 0-23. k counts 1-24 and K counts 0-11 — rarely what you want. | 15 |
| HH | Hour, 24-hour clock, padded | 15 |
| h | Hour, 12-hour clock Clock hour 1-12. | 3 |
| hh | Hour, 12-hour clock, padded | 03 |
| a | AM/PM marker Locale text; B gives day periods like 'in the morning'. | PM |
| mm | Minute, padded | 04 |
| ss | Second, padded | 05 |
| SSS | Fractional seconds One S per digit, up to nine (nanoseconds); the value is truncated, not rounded. n prints raw nano-of-second. | 000 |
| Z | UTC 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 |
| xxx | UTC offset, extended Always +00:00 at UTC; XXX is identical except it prints the letter Z for zero offset. | -07:00 |
| z | Time-zone name, short Short DST-aware name (PST); zzzz spells it out, v ignores daylight saving. | MST |
| G | Era | AD |
| Q | Quarter 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.