Why does Java's java.time.format.DateTimeFormatter#format(LocalDateTime) add a year?
Solution 1:
From Wikipedia:
[YYYY] indicates the ISO week-numbering year which is slightly different from the traditional Gregorian calendar year (see below).
-
YYYY
is an ISO-8601 style representation of the year. -
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
.