Convert seconds to Hour:Minute:Second

I need to convert seconds to "Hour:Minute:Second".

For example: "685" converted to "00:11:25"

How can I achieve this?


You can use the gmdate() function:

echo gmdate("H:i:s", 685);

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)