为什么格式化日期会返回错误的年份? [英] Why does formatting a date return the wrong year?

查看:153
本文介绍了为什么格式化日期会返回错误的年份?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的网页上打印格式化的日期。我有一个对象日期,我使用$ 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, 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.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆