答案 0 :(得分:3)
function timeConversion($totalSeconds) {
$interval = (new DateTime())->diff((new DateTime())->add(new DateInterval("PT${totalSeconds}S")));
return $interval->format("%hh %imin %ss");
}
答案 1 :(得分:1)
如果您只需要不到24小时,那么:
$totalSeconds = 12345;
$dt = new DateTime('@' . $totalSeconds);
echo $dt->format('H:i:s');
答案 2 :(得分:0)
我无法在这里找到它,所以我分享帮助其他需要它的人!
function timeConversion($totalSeconds) {
$minutesInAnHour = 60;
$secondsInAMinute = 60;
$secondsInAnHour = 3600;
$seconds = $totalSeconds%$secondsInAMinute;
$hours = (int)($totalSeconds/$secondsInAnHour);
$totalMinutes = $totalSeconds - $seconds;
$minutes = ($totalMinutes-$hours*$secondsInAnHour)/$minutesInAnHour;
return $hours . "h " . $minutes . "min " . $seconds . "s";
}