3v4l.org

run code in 300+ PHP versions simultaneously
<?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; $string1 = $date1->format('Y-m-d\TH:i:s'); print '--- Vancouver => UTC ---' . PHP_EOL; $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;
Output for 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
--- 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
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 --- 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

preferences:
184.58 ms | 402 KiB | 205 Q