Posts Tagged ‘hour’

Seconds to Hour : minutes : seconds

This item was filled under [ PHP ]

Seconds to Hour : minutes : seconds
function sec_to_time($sec)
{
$hr = 0;
$min = 0;
$time = array();
while (floor($sec/3600) > 0)
{
$hr++;
$sec-=3600;
}
while (floor($sec/60) > 0)
{
$min++;
$sec-=60;
}
$time['h'] = ($hr < 10) ? “0″.$hr : $hr;
$time['m'] = ($min < 10) ? “0″.$min : $min;
$time['s'] = ($sec < 10) ? “0″.$sec : $sec;
return $time;
}

Example:
$ora = sec_to_time(1400); // 1400 seconds
echo $ora['h'].” : ”.$ora['m'].” : ”.$ora['s'];
// 00 : 23 : 20
// that means 23 minutes and 20 seconds

Continue reading...

Tagged with: [ , , , , , ]
Update me when site is updated