How to get TimeZone Offset in PHP
[caption id="attachment_768" align="alignnone" width="502"] timezone[/caption]
[sourcecode language="php"]
function getOffsetByTimeZone($localTimeZone)
{
$time = new DateTime(date('Y-m-d H:i:s'), new DateTimeZone($localTimeZone));
$timezoneOffset = $time->format('P');
return $timezoneOffset;
}
[/sourcecode]
Call this function passing a local time zone as a string.
eg.
[sourcecode language="php"]
function getOffsetByTimeZone($localTimeZone)
{
$time = new DateTime(date('Y-m-d H:i:s'), new DateTimeZone($localTimeZone));
$timezoneOffset = $time->format('P');
return $timezoneOffset;
}
[/sourcecode]
Call this function passing a local time zone as a string.
eg.
getOffsetByTimeZone('America/New_York');
0 comments: