3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $date = new DateTime('2015-09-01+00:00'); var_dump($date); $date = $date->setTimezone(new DateTimeZone('-09:00')); var_dump($date); $date = $date->setTimezone(new DateTimeZone('+00:00')); var_dump($date); $date = new DateTimeImmutable('2015-09-01+00:00'); var_dump($date); $date = $date->setTimezone(new DateTimeZone('-09:00')); var_dump($date); $date = $date->setTimezone(new DateTimeZone('+00:00')); var_dump($date);
based on B1rTa
Output for 7.0.20, 7.1.5 - 7.2.0
object(DateTime)#1 (3) { ["date"]=> string(26) "2015-09-01 00:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } object(DateTime)#1 (3) { ["date"]=> string(26) "2015-08-31 15:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "-09:00" } object(DateTime)#1 (3) { ["date"]=> string(26) "2015-09-01 00:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2015-09-01 00:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } object(DateTimeImmutable)#3 (3) { ["date"]=> string(26) "2015-08-31 15:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "-09:00" } object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2015-09-01 00:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" }
Output for 5.5.24 - 7.0.6, 7.1.0
object(DateTime)#1 (3) { ["date"]=> string(26) "2015-09-01 00:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } object(DateTime)#1 (3) { ["date"]=> string(26) "2015-08-31 15:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "-09:00" } object(DateTime)#1 (3) { ["date"]=> string(26) "2015-08-31 15:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2015-09-01 00:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } object(DateTimeImmutable)#3 (3) { ["date"]=> string(26) "2015-08-31 15:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "-09:00" } object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2015-08-31 15:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" }
Output for 5.4.30 - 5.4.45
object(DateTime)#1 (3) { ["date"]=> string(26) "2015-09-01 00:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } Fatal error: Uncaught exception 'Exception' with message 'DateTimeZone::__construct(): Unknown or bad timezone (-09:00)' in /in/7S3VP:6 Stack trace: #0 /in/7S3VP(6): DateTimeZone->__construct('-09:00') #1 {main} thrown in /in/7S3VP on line 6
Process exited with code 255.
Output for 5.3.20 - 5.4.29
object(DateTime)#1 (3) { ["date"]=> string(19) "2015-09-01 00:00:00" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } Fatal error: Uncaught exception 'Exception' with message 'DateTimeZone::__construct(): Unknown or bad timezone (-09:00)' in /in/7S3VP:6 Stack trace: #0 /in/7S3VP(6): DateTimeZone->__construct('-09:00') #1 {main} thrown in /in/7S3VP on line 6
Process exited with code 255.