3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $nowUtc = new \DateTime( 'now', new \DateTimeZone( 'UTC' ) ); echo '$nowUtc'.PHP_EOL; var_dump($nowUtc); $nowUtc = new \DateTime( 'now', new \DateTimeZone( 'UTC' ) ); echo '$nowUtc->format(\'Y-m-d h:i:s\')'.PHP_EOL; var_dump($nowUtc->format('Y-m-d h:i:s')); $nowUtc->setTimezone( new \DateTimeZone( 'Australia/Sydney' ) ); echo '$nowUtc->setTimezone( new \DateTimeZone( \'Australia/Sydney\' ) )'.PHP_EOL; var_dump($nowUtc); echo '$nowUtc->format(\'Y-m-d h:i:s\')'.PHP_EOL; var_dump($nowUtc->format('Y-m-d h:i:s'));exit; ?>
Output for 7.1.0
$nowUtc object(DateTime)#1 (3) { ["date"]=> string(26) "2015-03-17 20:09:19.004059" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } $nowUtc->format('Y-m-d h:i:s') string(19) "2015-03-17 08:09:19" $nowUtc->setTimezone( new \DateTimeZone( 'Australia/Sydney' ) ) object(DateTime)#2 (3) { ["date"]=> string(26) "2015-03-18 07:09:19.004115" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Australia/Sydney" } $nowUtc->format('Y-m-d h:i:s') string(19) "2015-03-18 07:09:19"
Output for 5.4.30 - 5.4.45, 5.5.14 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.0.14
$nowUtc object(DateTime)#1 (3) { ["date"]=> string(26) "2015-03-17 20:09:19.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } $nowUtc->format('Y-m-d h:i:s') string(19) "2015-03-17 08:09:19" $nowUtc->setTimezone( new \DateTimeZone( 'Australia/Sydney' ) ) object(DateTime)#2 (3) { ["date"]=> string(26) "2015-03-18 07:09:19.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Australia/Sydney" } $nowUtc->format('Y-m-d h:i:s') string(19) "2015-03-18 07:09:19"
Output for 5.3.0 - 5.4.29, 5.5.0 - 5.5.13
$nowUtc object(DateTime)#1 (3) { ["date"]=> string(19) "2015-03-17 20:09:19" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } $nowUtc->format('Y-m-d h:i:s') string(19) "2015-03-17 08:09:19" $nowUtc->setTimezone( new \DateTimeZone( 'Australia/Sydney' ) ) object(DateTime)#2 (3) { ["date"]=> string(19) "2015-03-18 07:09:19" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Australia/Sydney" } $nowUtc->format('Y-m-d h:i:s') string(19) "2015-03-18 07:09:19"
Output for 5.2.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RvgcF on line 2 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RvgcF on line 2 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RvgcF on line 5 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RvgcF on line 5 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RvgcF on line 8 $nowUtc object(DateTime)#1 (0) { } $nowUtc->format('Y-m-d h:i:s') string(19) "2015-03-17 08:09:19" $nowUtc->setTimezone( new \DateTimeZone( 'Australia/Sydney' ) ) object(DateTime)#2 (0) { } $nowUtc->format('Y-m-d h:i:s') string(19) "2015-03-18 07:09:19"
Output for 5.0.0 - 5.1.6
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RvgcF on line 2 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RvgcF on line 2 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RvgcF on line 5 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RvgcF on line 5 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RvgcF on line 8 Fatal error: Class 'DateTime' not found in /in/RvgcF on line 2
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RvgcF on line 2 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RvgcF on line 2 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RvgcF on line 5 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RvgcF on line 5 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RvgcF on line 8 Fatal error: Cannot instantiate non-existent class: datetime in /in/RvgcF on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RvgcF on line 2 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RvgcF on line 2 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RvgcF on line 5 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RvgcF on line 5 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RvgcF on line 8 Fatal error: Cannot instantiate non-existent class: datetime in /in/RvgcF on line 2