Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP with IntlDateFormatter

Tags:

php

intl

There's a script:

for($i=80; $i<=89; $i++)
{
    $date = '01.04.19'.$i;
    $intlDateFormatter = new \IntlDateFormatter('ru', 2, -1, 'Europe/Moscow', 1, 'dd.MM.yyyy');
    $intlDateFormatter->setLenient(false);
    $timestamp = $intlDateFormatter->parse($date);
    echo $date . ' = ' . var_export($timestamp, 1);
    echo '<br>' . PHP_EOL;
}

And script outputs:

01.04.1980 = 323384400
01.04.1981 = false
01.04.1982 = false
01.04.1983 = false
01.04.1984 = false
01.04.1985 = 481147200
01.04.1986 = 512683200
01.04.1987 = 544219200
01.04.1988 = 575841600
01.04.1989 = 607377600

What's wrong with dates: 01.04.1981, 01.04.1982, 01.04.1983, 01.04.1984? PHP 5.5.9-1

like image 911
Alex Avatar asked Sep 27 '26 10:09

Alex


1 Answers

I think it is because in those years Moscow changed to Daylight Savings Time on April 1st so the time between 00:00:00 and 00:01:00 didn't exist. In 1985 they changed a day earlier and in 1980 they didn't change at all

You can see details of time/date changes at; http://www.timeanddate.com/time/change/russia/moscow?year=1982

like image 162
Mark_1 Avatar answered Sep 30 '26 00:09

Mark_1



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!