Last active
January 3, 2016 13:29
-
-
Save EpokK/8469685 to your computer and use it in GitHub Desktop.
How to retrieve timezone offset from GMT+0 in php?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function getStandardOffsetUTC($timezone) | |
{ | |
if($timezone == 'UTC') { | |
return ''; | |
} else { | |
$timezone = new DateTimeZone($timezone); | |
$transitions = array_slice($timezone->getTransitions(), -3, null, true); | |
foreach (array_reverse($transitions, true) as $transition) | |
{ | |
if ($transition['isdst'] == 1) | |
{ | |
continue; | |
} | |
return sprintf('UTC %+03d:%02u', $transition['offset'] / 3600, abs($transition['offset']) % 3600 / 60); | |
} | |
return false; | |
} | |
} | |
// usage | |
echo getStandardOffsetUTC('Europe/Sofia'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment