3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo 'date_default_timezone_get(): ' . print_r(date_default_timezone_get(), true) . "\n"; $ts = time(); echo '$ts: ' . print_r($ts, true) . "\n"; echo 'date(\'c\', $ts): ' . print_r(date('c', $ts), true) . "\n"; $datetime = new \Datetime(date('c', $ts)); echo '$datetime: ' . print_r($datetime, true) . "\n"; $datetime = new \Datetime('@' . $ts); echo '$datetime: ' . print_r($datetime, true) . "\n"; $datetime = new \Datetime('@' . $ts); $datetime->setTimezone(new \DateTimeZone(date_default_timezone_get())); echo '$datetime: ' . print_r($datetime, true) . "\n";
Output for 7.2.0 - 7.2.31, 7.3.0 - 7.3.19, 7.4.0 - 7.4.7
date_default_timezone_get(): Europe/Amsterdam $ts: 1592431437 date('c', $ts): 2020-06-18T00:03:57+02:00 $datetime: DateTime Object ( [date] => 2020-06-18 00:03:57.000000 [timezone_type] => 1 [timezone] => +02:00 ) $datetime: DateTime Object ( [date] => 2020-06-17 22:03:57.000000 [timezone_type] => 1 [timezone] => +00:00 ) $datetime: DateTime Object ( [date] => 2020-06-18 00:03:57.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam )

preferences:
60.2 ms | 407 KiB | 5 Q