Created
August 4, 2015 19:09
-
-
Save tomzx/abc1dc4b5860bc711e62 to your computer and use it in GitHub Desktop.
PHP Convert MySQL timezone format to PHP timezone
This file contains 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
function convertMySQLTimezone($timezone) | |
{ | |
$result = preg_match('/(?P<sign>\+|-)(?P<hours>\d{1,2}):(?P<minutes>\d{1,2})/', $timezone, $match); | |
if ( ! $result) { | |
return timezone_name_from_abbr('UTC'); | |
} | |
$sign = $match['sign'] === '-' ? -1 : 1; | |
$hours = $match['hours']; | |
$minutes = $match['minutes']; | |
$offset = $sign * (($hours * 60) + $minutes * 60) * 60; | |
return timezone_name_from_abbr('', $offset, 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment