Showing posts with label GMT. Show all posts
Showing posts with label GMT. Show all posts

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

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