I want to print formatted dates on my page. I have an object date and I use $this->Time->format() for formatting. Everything works fine before December 27th. Unfortunately a
Try specifying the date format as 'yyyy'
. The case is important.
debug($this->Time->format($date, 'yyyy'))
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.