3v4l.org

run code in 300+ PHP versions simultaneously
<?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)); }
Output for git.master, git.master_jit, rfc.property-hooks
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" } object(DateTime)#3 (3) { ["date"]=> string(26) "2009-01-05 12:34:56.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTime)#2 (3) { ["date"]=> string(26) "2009-01-05 12:34:56.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+01:00" } object(DateTime)#3 (3) { ["date"]=> string(26) "2009-01-05 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
43.68 ms | 402 KiB | 8 Q