gpt4 book ai didi

PHP IntlDateFormatter 格式返回错误的日期

转载 作者:行者123 更新时间:2023-12-04 03:06:45 27 4
gpt4 key购买 nike

我使用 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) 的日期。

我找不到问题所在。

感谢您的帮助。

最佳答案

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

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() 所说的,您必须更改操作系统上的时区。但是不要那样做

最好在调用 IntlDateFormatter::create() 时指定时区。如果你想使用 PHP 在别处使用的默认时区,可以用 date_default_timezone_get() 检索。 .

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

关于PHP IntlDateFormatter 格式返回错误的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9499830/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com