Why does Java’s java.time.format.DateTimeFormatter#format(LocalDateTime) add a year?

From Wikipedia:

[YYYY] indicates the ISO week-numbering year which is slightly
different from the traditional Gregorian calendar year (see below).

  1. YYYY is an ISO-8601 style representation of the year.
  2. yyyy is the Gregorian year-of-era representation.

Since the the calculation of the two can be different by +1 or -1, hence the formatting. More useful info at YEAR_OF_ERA, YEAR, and weekBasedYear.

Leave a Comment