As @Andy Turner pointed out in the comments, the problem comes from this statement:
DateTimeFormatter displayFormatter = DateTimeFormatter.ofPattern("MMMM d, YYYY");
where, according to the docs, Y
means a week-based-year
, y
means year-of-era
, and u
means simply year
.
Therefore, these two variants should produce the correct year for you:
DateTimeFormatter displayFormatter = DateTimeFormatter.ofPattern("MMMM d, yyyy");
DateTimeFormatter displayFormatter = DateTimeFormatter.ofPattern("MMMM d, uuuu");
Now to understand why y
and Y
are different and why do they lead to your problem, I found this already discussed here on SO: https://stackoverflow.com/a/62690443/9698467
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…