Skip to content

Instantly share code, notes, and snippets.

@tomzx
Created August 4, 2015 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomzx/abc1dc4b5860bc711e62 to your computer and use it in GitHub Desktop.
Save tomzx/abc1dc4b5860bc711e62 to your computer and use it in GitHub Desktop.
PHP Convert MySQL timezone format to PHP timezone
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