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) { $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");
Output for 5.3.0 - 7.1.0
512:10
Output for 5.2.3 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Koa3o on line 16 Fatal error: Class 'DateInterval' not found in /in/Koa3o on line 16
Process exited with code 255.
Output for 5.0.0 - 5.2.2
<br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/Koa3o</b> on line <b>16</b><br /> <br /> <b>Fatal error</b>: Class 'DateInterval' not found in <b>/in/Koa3o</b> on line <b>16</b><br />
Process exited with code 255.
Output for 4.4.2 - 4.4.9
<br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/Koa3o</b> on line <b>16</b><br /> <br /> <b>Parse error</b>: syntax error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' in <b>/in/Koa3o</b> on line <b>20</b><br />
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
<br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/Koa3o</b> on line <b>16</b><br /> <br /> <b>Parse error</b>: parse error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' in <b>/in/Koa3o</b> on line <b>20</b><br />
Process exited with code 255.
Output for 4.3.2 - 4.3.4
<br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/Koa3o</b> on line <b>16</b><br /> <br /> <b>Parse error</b>: parse error, expecting `','' or `';'' in <b>/in/Koa3o</b> on line <b>20</b><br />
Process exited with code 255.