Thursday, March 10, 2011

PHP Convert local time to GMT time

Get user timezone offset(ex. Timezone offset for nepal +5:45)

$userTzOffset = +5:45
$userDateTime = "2011-03-10 14:00"

$osts = explode(":",$userTzOffset);
$secs = ($osts[0] * 60 * 60) + $osts[1] * 60 ;
$userTimeStamp = strtotime(date('Y-m-d H:i:s',time()+$secs));
$dt = date('Y-m-d H:i:s',strtotime($dateTime,$userTimeStamp) - $sec);
echo $dt;


Related Post PHP Convert GMT time to local time

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

No comments:

Post a Comment