Thursday, March 10, 2011

PHP Convert GMT time to local time

Get user timezone offset(ex. Timezone offset for nepal +5:45)
$userTzOffset = +5:45
$gmtDateTime = "2011-03-10 9:00"
$osts = explode(":",$userTzOffset);
$sec = ($osts[0] * 60 * 60) + $osts[1] * 60 ;
$gmtTimeStamp = strtotime($gmtDateTime, time()) + $sec;
$dt = date('Y-m-d::H:i:s',$gmtTimeStamp);

echo $dt;
Hope this will help someone.

Related post PHP Convert local time to GMT time

For getting timezone and offset see this post Get TimeZone with Daylight saving in PHP

No comments:

Post a Comment