3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function strToDuration($str) { sscanf($str, '%d:%d:%d', $hours, $minutes, $seconds); return $seconds + ($minutes * 60) + ($hours * 60 * 60); } function durationToStr($duration) { $hours = floor($duration / (60 * 60)); $seconds %= 60 * 60; $minutes = floor($seconds / 60); $seconds %= 60; return sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds); } $morning = '01:05:12'; $evening = '14:05:29'; echo durationToStr(strToDuration($morning) + strToDuration($evening));
Output for 5.0.4 - 5.6.28, 7.0.0 - 7.1.0
Notice: Undefined variable: seconds in /in/HgecZ on line 10 15:00:00
Output for hhvm-3.10.0 - 3.12.0
15:00:00
Output for 4.3.0 - 5.0.3
Notice: Undefined variable: seconds in /in/HgecZ on line 10 15:00:00