PHP IntlDateFormatter格式返回错误的日期 [英] PHP IntlDateFormatter format returns wrong date

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

问题描述

我使用IntlDateFormatter得到不正确的结果:

I'm getting incorrect results using IntlDateFormatter:

$dateFormater = \IntlDateFormatter::create(
'en_EN',
\IntlDateFormatter::LONG,
\IntlDateFormatter::NONE
);

$a = date('Y/m/d H:i:s',1332712800); //2012/03/26 00:00:00
$b = $dateFormater->format(1332712800); //March 25, 2012

但这只发生在2012/03/26和2012 / 10/28,没有小时(00:00:00)。

But this only happens for dates between 2012/03/26 and 2012/10/28 and without hour (00:00:00).

我找不到什么问题。

感谢您的帮助。

推荐答案

http://userguide.icu-project.org/datetime/timezone#TOC-Factory-Methods-and- the-Default-Tim


TimeZone 保持静态时间被称为默认时区的区域对象。这是当用户未指定时间时隐式使用的时区。 ICU尝试将其与主机操作系统时区相匹配。

TimeZone maintains a static time zone object known as the default time zone. This is the time zone that is used implicitly when the user does not specify one. ICU attempts to match this to the host OS time zone.

简而言之,如果要更改默认时区从intl匹配什么 date()说,您必须更改操作系统上的时区。但是不要这样做

In short, if you want to change the default timezone from intl to match what date() says, you must change the time zone on your operating system. But don't do that.

最好在调用 IntlDateFormatter create()。如果您希望使用PHP在其他地方使用的默认时区,则可以使用 date_default_timezone_get()

It is preferred that you specify the timezone in the call to IntlDateFormatter::create(). If you wish to use the default timezone that PHP is using elsewhere, that can be retrieved with date_default_timezone_get().

$dateFormater = \IntlDateFormatter::create(
    'en_EN',
    \IntlDateFormatter::LONG,
    \IntlDateFormatter::NONE,
    date_default_timezone_get()
);

这篇关于PHP IntlDateFormatter格式返回错误的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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