3v4l.org - online PHP & HHVM shell, execute code in 100+ different versions!

<?php /** * Converts a 'decimal time' in the format 1.5hours to DateInterval object * * @param Int $decimalTime * @return DateInterval */ function decTimeToInterval($decimalTime) { $hours = floor($decimalTime); $decimalTime -= $hours; $minutes = floor($decimalTime * 60); $decimalTime -= ($minutes/60); $seconds = floor($decimalTime * 600); $interval = new \DateInterval("PT{$hours}H{$minutes}M{$seconds}S"); return $interval; } echo decTimeToInterval(512.168)->format("%H:%I:%S");
Output for 5.3.0 - 5.6.3, php7@20140507 - 20141101, hhvm-3.0.1 - 3.4.0
512:10:00
Output for 5.0.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/qU5M4 on line 16 Fatal error: Class 'DateInterval' not found in /in/qU5M4 on line 16
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/qU5M4 on line 16 Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' in /in/qU5M4 on line 20
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/qU5M4 on line 16 Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' in /in/qU5M4 on line 20
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/qU5M4 on line 16 Parse error: parse error, expecting `','' or `';'' in /in/qU5M4 on line 20
Process exited with code 255.