Reputation: 3471
Is there a function in PHP to get a date when timezones UTC offset is changing? For example:
$date1 = new DateTime('27.03.2016 03:00:00', new DateTimeZone('Europe/Warsaw') );
echo $date1->getOffset();
It returns 7200.
And this:
$date2 = new DateTime('27.03.2016 01:00:00', new DateTimeZone('Europe/Warsaw') );
echo $date2->getOffset();
returns 3600. By running this I know UTC offset in specific date, but I don't know the exact date when this UTC is changing.
Of course I could loop trough all days in a year (with minutes precise), and find out the specic time but... PHP know this date and I think there must be a way - simple function to get it! Can't find anything at: http://php.net/manual/en/book.datetime.php
Upvotes: 1
Views: 164
Reputation: 1577
You can use the DateTimeZone::getTransitions()
:
$timezone = new DateTimeZone("Europe/Berlin");
print_r($timezone->getTransitions());
will print something like:
[101] => Array
(
[ts] => 1445734800
[time] => 2015-10-25T01:00:00+0000
[offset] => 3600
[isdst] =>
[abbr] => CET
)
[102] => Array
(
[ts] => 1459040400
[time] => 2016-03-27T01:00:00+0000
[offset] => 7200
[isdst] => 1
[abbr] => CEST
)
[103] => Array
(
[ts] => 1477789200
[time] => 2016-10-30T01:00:00+0000
[offset] => 3600
[isdst] =>
[abbr] => CET
)
[104] => Array
(
[ts] => 1490490000
[time] => 2017-03-26T01:00:00+0000
[offset] => 7200
[isdst] => 1
[abbr] => CEST
)
You can limit the transitions you want with the start and end date parameters.
Upvotes: 2