3v4l.org

run code in 300+ PHP versions simultaneously
<?php $currentTimezone = new DateTimeZone(date_default_timezone_get()); $timestamp = time(); $date = new DateTime('@' . $timestamp); $date2 = new DateTime(); $date2->modify('@' . $timestamp); $date3 = new DateTime(); $date3->setTimestamp($timestamp); var_dump($date->format('Y-m-d H:i:s e')); $date->setTimezone($currentTimezone); var_dump($date->format('Y-m-d H:i:s e')); //update timezone var_dump($date2->format('Y-m-d H:i:s e')); var_dump($date3->format('Y-m-d H:i:s e'));
Output for 5.3.6 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.25, 7.4.0 - 7.4.13, 8.0.0
string(26) "2021-01-01 15:10:42 +00:00" string(36) "2021-01-01 16:10:42 Europe/Amsterdam" string(36) "2021-01-01 15:10:42 Europe/Amsterdam" string(36) "2021-01-01 16:10:42 Europe/Amsterdam"
Output for 5.3.0 - 5.3.5
string(26) "2021-01-01 15:10:42 +00:00" string(36) "2021-01-01 16:10:42 Europe/Amsterdam" string(36) "2072-01-03 07:21:24 Europe/Amsterdam" string(36) "2021-01-01 16:10:42 Europe/Amsterdam"
Output for 5.2.0 - 5.2.17
Fatal error: Call to undefined method DateTime::setTimestamp() in /in/BoAWI on line 9
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6
Fatal error: Class 'DateTimeZone' not found in /in/BoAWI on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.9
Fatal error: Cannot instantiate non-existent class: datetimezone in /in/BoAWI on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: datetimezone in /in/BoAWI on line 2

preferences:
248.82 ms | 401 KiB | 358 Q