function duration($time){
$hours = '';
$minutes = '00:';
$seconds = '00';
if($time >= 3600){
//0 - ~ hours
$hours = floor($time / 3600);
$hours = str_pad($hours, 2, '0', STR_PAD_LEFT) . ':';
$time = $time % 3600;
}
if($time >= 60){
//0 - 60 minute
$minutes = floor($time / 60);
$minutes = str_pad($minutes, 2, '0', STR_PAD_LEFT) . ':';
$time = $time % 60;
}
if($time){
//0 - 60 second
$seconds = str_pad($time, 2, '0', STR_PAD_LEFT);
}
return $hours . $minutes . $seconds;
}
echo duration(59); // 00:59
echo duration(590); // 09:50
echo duration(5900); // 01:38:20
задан htafoya 13 July 2018 в 15:43
поделиться