Like us on Facebook and stand a chance to win pen drives!

How to get TimeZone Offset in PHP

[caption id="attachment_768" align="alignnone" width="502"]timezone 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.
getOffsetByTimeZone('America/New_York');


0 comments:

Copyright © 2012 The Code Junction.