3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php /** * Converts a 'decimal time' in the format 1.5hours to DateInterval object * * @param Int $decimalTime * @return DateInterval */ function decTimeToInterval($decimalTime) { $seconds = round($decimalTime * 3600); $interval = \DateInterval::createFromDateString("$seconds seconds"); $start = new \DateTime(); $end = clone($start); $end->add($interval); $interval = $start->diff($end); return $interval; } echo decTimeToInterval(12.33)->format("%H:%I:%S");
Output for 5.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
12:19:48
Output for 5.0.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/0c3f6 on line 11 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/0c3f6 on line 12 Fatal error: Class 'DateInterval' not found in /in/0c3f6 on line 11
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/0c3f6 on line 11 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/0c3f6 on line 12 Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' in /in/0c3f6 on line 19
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/0c3f6 on line 11 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/0c3f6 on line 12 Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' in /in/0c3f6 on line 19
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/0c3f6 on line 11 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/0c3f6 on line 12 Parse error: parse error, expecting `','' or `';'' in /in/0c3f6 on line 19
Process exited with code 255.