Monday, August 17, 2015

Server Time Zone to Local TimeZone in PHP

Barbie would have said, 'Time Math is Hard'.

JS to get TZ



PHP:
$myTZ = 'America/New_York'; //time zone that date/time is stored in
$urTZ = $row['timezone']; // stored local
$local_time_in = new DateTime($row['time_in'], new DateTimeZone($myTZ));
$local_time_out = new DateTime($row['time_out'],new DateTimeZone($myTZ));
$local_time_in->setTimeZone(new DateTimeZone($urTZ));
$local_time_out->setTimeZone(new DateTimeZone($urTZ));
$row['local_time_in'] = $local_time_in->format('Y-m-d H:i T');
$row['local_time_out'] =$local_time_out->format('Y-m-d H:i T');
                   

No comments: