问题
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
But this only happens for dates between 2012/03/26 and 2012/10/28 and without hour (00:00:00).
I can't find out what is the problem.
Thanks for the help.
回答1:
http://userguide.icu-project.org/datetime/timezone#TOC-Factory-Methods-and-the-Default-Tim says
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.
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.
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()
);
来源:https://stackoverflow.com/questions/9499830/php-intldateformatter-format-returns-wrong-date