- floor: documentation ( source)
- explode: documentation ( source)
- sprintf: documentation ( source)
<?php
function seconds_from_time($time) {
list($h, $m, $s) = explode(':', $time);
return ($h * 3600) + ($m * 60) + $s;
}
function time_from_seconds($seconds) {
$h = floor($seconds / 3600);
$m = floor(($seconds % 3600) / 60);
$s = $seconds - ($h * 3600) - ($m * 60);
return sprintf('%02d:%02d:%02d', $h, $m, $s);
}
echo seconds_from_time("18:27:31");
echo '<br />';
echo time_from_seconds(66451);
?>