문제

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.

도움이 되었습니까?

해결책

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()
);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top