Monday, July 7, 2014

Php, convert time between two timezones


<?php
$src_tz = new DateTimeZone('Australia/Melbourne');
$dest_tz = new DateTimeZone('GMT');

$dt = new DateTime("2014-07-06 00:00:00", $src_tz);
echo 'Australia/Melbourne: ' . $dt->format('Y-m-d H:i:s');
$dt->setTimeZone($dest_tz);
echo '<br/>GMT: ' . $dt->format('Y-m-d H:i:s');

$dt = new DateTime("2014-10-06 00:00:00", $src_tz);
echo '<br/><br/>Australia/Melbourne: ' . $dt->format('Y-m-d H:i:s');
$dt->setTimeZone($dest_tz);
echo '<br/>GMT (DST Enabled): ' . $dt->format('Y-m-d H:i:s');
?>

Output

Australia/Melbourne: 2014-07-06 00:00:00
GMT: 2014-07-05 14:00:00

Australia/Melbourne: 2014-10-06 00:00:00
GMT (DST Enabled): 2014-10-05 13:00:00

No comments:

Post a Comment