I need to convert seconds to \"Hour:Minute:Second\".
For example: \"685\" converted to \"00:11:25\"
How can I achieve this?
Try this:
date("H:i:s",-57600 + 685);
Taken from
http://bytes.com/topic/php/answers/3917-seconds-converted-hh-mm-ss
The following codes can display total hours plus minutes and seconds accurately
$duration_in_seconds = 86401;
if($duration_in_seconds>0)
{
echo floor($duration_in_seconds/3600).gmdate(":i:s", $duration_in_seconds%3600);
}
else
{
echo "00:00:00";
}
write function like this to return an array
function secondsToTime($seconds) {
// extract hours
$hours = floor($seconds / (60 * 60));
// extract minutes
$divisor_for_minutes = $seconds % (60 * 60);
$minutes = floor($divisor_for_minutes / 60);
// extract the remaining seconds
$divisor_for_seconds = $divisor_for_minutes % 60;
$seconds = ceil($divisor_for_seconds);
// return the final array
$obj = array(
"h" => (int) $hours,
"m" => (int) $minutes,
"s" => (int) $seconds,
);
return $obj;
}
then simply call the function like this:
secondsToTime(100);
output is
Array ( [h] => 0 [m] => 1 [s] => 40 )