Using DateTimeFormatter
(with the pattern below) with a LocalDate
results in the wrong year.
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
DateTimeFormatter format = DateTimeFormatter.ofPattern("MM-d-YYYY");
LocalDate date = LocalDate.of(2018, 12, 31);
date.format(format); // returns 12-31-2019 (expected 2018)
Why does this happen?