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']); var_dump($matches); //$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)); }