3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $dateTimeExample = new DateTime('2009-01-05 12:34:56'); $dateTimes = [ $dateTimeExample->format('Y-m-d H:i:s'), $dateTimeExample->format('c'), $dateTimeExample->format('Y-m-d') ]; var_dump($dateTimes); foreach($dateTimes as $input){ preg_match('~(?<date>\d{4}-\d{2}-\d{2})[\s|T]?(?<time>\d{2}:\d{2}:\d{2})?(?<timezone>[\+|-]\d{2}:\d{2})?~', $input, $matches); $matches['time'] = array_key_exists('time', $matches) ? $matches['time'] : '00:00:00'; $dateTime = sprintf('%s %s', $matches['date'], $matches['time']); $timeZone = array_key_exists('timezone', $matches) ? new \DateTimeZone($matches['timezone']) : new \DateTimeZone('Europe/Amsterdam'); var_dump(\DateTime::createFromFormat('Y-m-d H:i:s', $dateTime, $timeZone)->format('c')); }
Output for 5.6.30, 7.0.0 - 7.2.11
array(3) { [0]=> string(19) "2009-01-05 12:34:56" [1]=> string(25) "2009-01-05T12:34:56+01:00" [2]=> string(10) "2009-01-05" } string(25) "2009-01-05T12:34:56+01:00" string(25) "2009-01-05T12:34:56+01:00" string(25) "2009-01-05T00:00:00+01:00"
Output for hhvm-3.18.4, hhvm-3.22.0
array(3) { [0]=> string(19) "2009-01-05 12:34:56" [1]=> string(25) "2009-01-05T12:34:56+01:00" [2]=> string(10) "2009-01-05" } string(25) "2009-01-05T12:34:56+01:00" Fatal error: Uncaught exception 'Exception' with message 'DateTimeZone::__construct(): Unknown or bad timezone (+01:00)' in /in/E2D3u:-1 Stack trace: #0 /in/E2D3u(-1): DateTimeZone->__construct() #1 {main}
Process exited with code 255.
Output for hhvm-3.15.4, hhvm-3.18.5 - 3.21.3
array(3) { [0]=> string(19) "2009-01-05 12:34:56" [1]=> string(25) "2009-01-05T12:34:56+01:00" [2]=> string(10) "2009-01-05" } string(25) "2009-01-05T12:34:56+01:00" Fatal error: Uncaught exception 'Exception' with message 'DateTimeZone::__construct(): Unknown or bad timezone (+01:00)' in /in/E2D3u:19 Stack trace: #0 /in/E2D3u(19): DateTimeZone->__construct() #1 {main}
Process exited with code 255.