Java DataFormat的“Y”是什么?

学艺不精,以为YYYYyyyy可以一样用,结果翻车了……

根据Oracle Java SE 7的文档,可以知道小写y指的是年,大写Y指的是Week Year。但是Week Year是什么东东?

开始无脑引用(参考资料1):

The week of a week-based year can also be defined in different ways.

  1. Week # 1 contains January 1.
  2. Week # 1 is the first week to contain a particular day-of-week such as Sunday.

MD,看了一圈下来发现:Week Year基于周的定义来计算年,且在标准Java环境下,Week Year在和Week in year(Letter w)和Day number of week(Letter u)联用的情况下才能正常工作。在Y与别的Letter混用的情况下,别的值不能正常使用,值会被认为是1。(Since you supplied a week-year but did not supply day of week and week in year, those to values have been assumed as 1.

不过在Pega环境下,Y似乎不按照Java基本法发挥作用,“YYYY-MM-DD”居然会被认为是“自然年-月-Day in year”,太神奇了。

参考资料

  1. How does Java “week year” really work?