I need to convert seconds to Hour:Minute:Second
for example : 685 converted to 00:11:25
can you please help me achieve this
thanks
I need to convert seconds to Hour:Minute:Second
for example : 685 converted to 00:11:25
can you please help me achieve this
thanks
Try this:
date("H:i:s",-57600 + 685);
Taken from
http://bytes.com/topic/php/answers/3917-seconds-converted-hh-mm-ss
One hour is 3600sec, one minute is 60sec so why not:
<?php
$init = 685;
$hours = floor($init / 3600);
$minutes = floor(($init / 60) % 60);
$seconds = $init % 60;
echo "$hours:$minutes:$seconds";
?>
which produces:
$ php file.php
0:11:25
(I've not tested this much, so there might be errors with floor or so)
here you go
function format_time($t,$f=':') // t = seconds, f = separator
{
return sprintf("%02d%s%02d%s%02d", floor($t/3600), $f, ($t/60)%60, $f, $t%60);
}
echo format_time(685); // 00:11:25