3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $vancouver = new \DateTimeZone('America/Vancouver'); $utc = new \DateTimeZone('UTC'); $timestamp1 = 1478422920; $date1 = new \DateTime('@' . $timestamp1); print '--- UTC ---' . PHP_EOL; print $timestamp1 . PHP_EOL; print $date1->format('c') . PHP_EOL; print '--- UTC => Vancouver ---' . PHP_EOL; $date1->setTimezone($vancouver); print $date1->format('c') . PHP_EOL; print $date1->format('Y-m-d\TH:i:s') . PHP_EOL; print '--- Vancouver => UTC ---' . PHP_EOL; $string1 = $date1->format('Y-m-d\TH:i:s'); $date2 = new \DateTime($string1, $vancouver); $timestamp2 = $date2->getTimestamp(); print $timestamp2 . PHP_EOL; print $date2->format('c') . PHP_EOL; $date2->setTimezone($utc); print $date2->format('c') . PHP_EOL;
based on te3ND
Output for 5.6.0 - 7.3.0alpha1
--- UTC --- 1478422920 2016-11-06T09:02:00+00:00 --- UTC => Vancouver --- 2016-11-06T01:02:00-08:00 2016-11-06T01:02:00 --- Vancouver => UTC --- 1478419320 2016-11-06T01:02:00-07:00 2016-11-06T08:02:00+00:00