Why does formatting a date return the wrong year?

若如初见. 提交于 2019-11-29 15:54:49

i18n dates are formatted using IntlDateFormatter, which use ISO date format patterns, where YYYY doesn't just mean Full year, but Full week-numbering year, wich will return 2016 because the week of the day 2015-12-30 spans into the next year, or more specifically, because that week includes January the 1st that is still a weekday (Monday to Friday), thus it's being treated as the first week of 2016 according to the ISO week rules.

See also https://en.wikipedia.org/wiki/ISO_8601#Week_dates

You want to use yyyy instead, which will return the regular calendar year.

Try specifying the date format as 'yyyy'. The case is important.

debug($this->Time->format($date, 'yyyy'))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!