3v4l.org

run code in 300+ PHP versions simultaneously
<?php foreach (['Etc/GMT+12', 'Etc/GMT-10'] as $timezone) { $dTZ = new DateTimeZone($timezone); // Create a DateTime using the DateTimeZone object // This will display both formatted and unix timestamp as expected $dT = new DateTime('2013-12-13 18:49:00', $dTZ); echo $dT->format('Y-m-d H:i:s T'), PHP_EOL; echo $dT->getTimestamp(), PHP_EOL; // Create a DateTime using only a string representation // This will display the formatted date/time as expected, // but with the incorrect timezone // The value returned by getTimestamp() for format('U') will // be off by 2*offset $dT2 = new DateTime($dT->format('Y-m-d H:i:s T')); echo $dT2->format('Y-m-d H:i:s T'), PHP_EOL; echo $dT2->getTimestamp(), PHP_EOL, PHP_EOL; }
Output for 5.6.28 - 5.6.30, 7.0.13 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.13, 8.1.15 - 8.1.28, 8.2.0, 8.2.2 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
2013-12-13 18:49:00 -12 1387003740 2013-12-13 18:49:00 GMT-1200 1387003740 2013-12-13 18:49:00 +10 1386924540 2013-12-13 18:49:00 GMT+1000 1386924540
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 2013-12-13 18:49:00 -12 1387003740 2013-12-13 18:49:00 GMT-1200 1387003740 2013-12-13 18:49:00 +10 1386924540 2013-12-13 18:49:00 GMT+1000 1386924540
Output for 8.1.14, 8.2.1
Fatal error: Uncaught Exception: DateTimeZone::__construct(): Unknown or bad timezone (Etc/GMT+12) in /in/RCA06:4 Stack trace: #0 /in/RCA06(4): DateTimeZone->__construct('Etc/GMT+12') #1 {main} thrown in /in/RCA06 on line 4
Process exited with code 255.
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.27, 7.0.0 - 7.0.12
2013-12-13 18:49:00 GMT+12 1387003740 2013-12-13 18:49:00 GMT+1200 1386917340 2013-12-13 18:49:00 GMT-10 1386924540 2013-12-13 18:49:00 GMT-1000 1386996540
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/RCA06 on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/RCA06 on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/RCA06 on line 3
Process exited with code 255.

preferences:
335.9 ms | 401 KiB | 370 Q