3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface DateFormatParser { /** * @param $string * * @return DateTime */ public function parse($string); } abstract class PregDateParser implements DateFormatParser { protected $pattern, $format, $mask; public function parse($string) { $string = (string)$string; $pattern = $this->pattern; $format = $this->format; $mask = $this->mask; $r = preg_match($pattern, $string, $matches); if (!$r) { throw new UnexpectedValueException('Preg Regex Pattern failed.'); } $buffer = vsprintf($mask, $matches); $result = DateTime::createFromFormat($format, $buffer); if (!$result) { throw new UnexpectedValueException(sprintf('Failed To Create from Format "%s" for "%s".', $format, $buffer)); } return $result; } } class JsonTimestampWithOffsetParser extends PregDateParser { protected $pattern = '/^\/Date\((\d{10})(\d{3})([+-]\d{4})\)\/$/'; protected $format = 'U.u.O'; protected $mask = '%2$s.%3$s.%4$s'; } $date = '/Date(1440960660000-0200)/'; $parser = new JsonTimestampWithOffsetParser; $dt = $parser->parse($date); //$dt->modify(); $timezoneShift = $dt->format('Z'); $timezoneShift = ($timezoneShift > 0) ? '+' . $timezoneShift : '-' . $timezoneShift; echo $dt->modify($timezoneShift)->format('Y-m-d H:i:s');
Output for git.master, git.master_jit
Warning: DateTime::modify(): Failed to parse time string (--7200) at position 0 (-): Unexpected character in /in/9QJVq on line 52 Fatal error: Uncaught Error: Call to a member function format() on bool in /in/9QJVq:52 Stack trace: #0 {main} thrown in /in/9QJVq on line 52
Process exited with code 255.
Output for rfc.property-hooks
Fatal error: Uncaught DateMalformedStringException: DateTime::modify(): Failed to parse time string (--7200) at position 0 (-): Unexpected character in /in/9QJVq:52 Stack trace: #0 /in/9QJVq(52): DateTime->modify('--7200') #1 {main} thrown in /in/9QJVq on line 52
Process exited with code 255.

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:
49.18 ms | 401 KiB | 8 Q