Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why PHP IntlDateFormatter returns wrong date? +1 hour

Tags:

date

php

When I try to format date from one timezone to same timezone I get wrong time (differenced by 1 hour). My code is:

$formatter = new IntlDateFormatter(
    'ru_RU',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'Europe/Moscow'
);

$date = new DateTime("2015-07-29 14:00:00", new DateTimeZone('Europe/Moscow'));
echo $formatter->format($date);

Expected time is 14:00, but 15:00 returns.

UPDATE: When I display year 2013 or 2014 everything is ok! What happens in 2015?

UPDATE2: +1 hour added from 26 october 2014. Its time when Russia goes to eternal winter time. Ok. But... how to format correctly?

like image 468
psylosss Avatar asked Jul 29 '15 17:07

psylosss


2 Answers

I use directly 'GMT+03:00' instead 'Europe/Moscow'. Apparently the developers of the library do not have time for lawmakers.

like image 182
Serge Kraev Avatar answered Nov 03 '22 06:11

Serge Kraev


If you have same problem, update icu (International Components for Unicode) at your OS.

like image 33
psylosss Avatar answered Nov 03 '22 06:11

psylosss