將秒數轉換成時分秒,PHP提供了一個函數gmstrftime,不過該函數僅限於24小時內的秒數轉換。對於超過24小時的秒數,我們應該怎麼讓其顯示出來呢,例如 34:02:02
$seconds = 3600*34 + 122;
function changeTimeType($seconds){
if ($seconds > 3600){
$hours = intval($seconds/3600);
$minutes = $seconds % 3600;
$time = $hours.":".gmstrftime('%M:%S', $minutes);
}else{
$time = gmstrftime('%H:%M:%S', $seconds);
}
return $time;
}
echo changeTimeType($seconds);
結果輸出 34:02:02