Wednesday, March 20, 2013

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');

No comments:

Post a Comment

How to enable CORS in Laravel 5

https://www.youtube.com/watch?v=PozYTvmgcVE 1. Add middleware php artisan make:middleware Cors return $next($request) ->header('Acces...