DateTimeFormatter 一直不工作,错误?

DateTimeFormatter not working all the time, bug?

我在 运行 一些代码时遇到了一个奇怪的错误。这是一个简单的版本来展示相同的内容。

public class DateTest {

    public static void main(String[] args) {

        LocalDate decLast = LocalDate.of(2015, 12, 31);
        LocalDate novLast = LocalDate.of(2015, 11, 30);
        LocalDate octLast = LocalDate.of(2015, 10, 31);

        System.out.println(decLast+" "+novLast+" "+octLast);

        System.out.println(decLast.format(DateTimeFormatter.ofPattern("dd M YY"))+" "
                +novLast.format(DateTimeFormatter.ofPattern("dd M YY"))+" "
                +octLast.format(DateTimeFormatter.ofPattern("dd M YY")));


    }
}

这返回了以下结果

2015-12-31 2015-11-30 2015-10-31
31/12/16 30/11/15 31/10/15

不知何故,2015 年 12 月 31 日被转换为 2016 年 12 月 31 日。 我写了一个 for 循环来为不同的年份做同样的事情,发现很多年份都有变化。对于 12 月 26 日之后的任何日期,该错误都不存在。这是一个错误还是我在这里遗漏了什么?

大写的Y是“week based year”,您要找的是小写的y

来自链接的维基百科文章(我强调):

An ISO week-numbering year (also called ISO year informally) has 52 or 53 full weeks. That is 364 or 371 days instead of the usual 365 or 366 days. The extra week is referred to here as a leap week, although ISO 8601 does not use this term. Weeks start with Monday. The first week of a year is the week that contains the first Thursday of the year (and, hence, always contains 4 January). ISO week year numbering therefore slightly deviates from the Gregorian for some days close to 1 January.

[...]

For example, 29 December 2014 is ISO 2015-W1-1, i.e., it is in year 2015 instead of 2014.

比照。还有:https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html