为什么格式化日期会返回错误的年份? [英] Why does formatting a date return the wrong year?
问题描述
我想在我的网页上打印格式化的日期。我有一个对象日期,我使用$ this-> Time-> format()进行格式化。一切工作正常在12月27日之前。很遗憾,在12月26日之后的所有日期,格式都改变了我的年份。
这是我的调试($ date)
object(Cake\I18n\Time){
'time'=> '2015-12-30T00:00:00 + 0000',
'timezone'=> 'UTC',
'fixedNowTime'=> false
}
这是我的调试($ this-> Time- > format($ date,'YYYY'))
'2016'
/ pre>
我试图使用i18nFormat,但我有同样的问题。这是我的调试($ date-> i18nFormat('YYYY'));
'2016'
<感谢您的帮助解决方案p> i18n日期使用
IntlDateFormatter
格式化,它使用ISO日期格式模式,其中YYYY
strong>全年,但全周编号年,将返回2016
,因为一周<$ c $
另请参阅 https://en.wikipedia.org/wiki/ISO_8601#Week_dates
您希望改用
yyyy
,这将返回常规全年。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 all dates after the December 26th, formatting change my year number.
This is my debug($date)
object(Cake\I18n\Time) { 'time' => '2015-12-30T00:00:00+0000', 'timezone' => 'UTC', 'fixedNowTime' => false }
This is my debug($this->Time->format($date, 'YYYY'))
'2016'
I tried to use i18nFormat but I have the same problem. Here is my debug($date->i18nFormat('YYYY'));
'2016'
Thanks for your help
解决方案i18n dates are formatted using
IntlDateFormatter
, which use ISO date format patterns, whereYYYY
doesn't just mean Full year, but Full week-numbering year, wich will return2016
because the week of the day2015-12-30
spans into the next year.See also https://en.wikipedia.org/wiki/ISO_8601#Week_dates
You want to use
yyyy
instead, which will return the regular full year.这篇关于为什么格式化日期会返回错误的年份?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!