如何在php中将HH:MM:SS时间转换为天数:HH:MM:SS


How to convert HH:MM:SS time to number of days:HH:MM:SS in php

我需要将时间28:10:10 (HH:MM:SS)转换为1:04:10:10 (Day:HH:MM:SS)。我想使用apply strtime()函数将输入时间转换为24小时时间格式。

我还需要从它减去一个给定的时间

**I have tried to answer your question. below is the code that will give you correct output. pls have a look on the below code.**
function secondsToTime($ss) {
        $s = $ss%60;
        $m = floor(($ss%3600)/60);
        $h = floor(($ss%86400)/3600);
        $d = floor(($ss%2592000)/86400); 
        // Ensure all values are 2 digits, prepending zero if necessary.
        $s = $s < 10 ? '0' . $s : $s;
        $m = $m < 10 ? '0' . $m : $m;
        $h = $h < 10 ? '0' . $h : $h;
        $d = $d < 10 ? '0' . $d : $d;
        return "$d:$h:$m:$s";
    }

    $time = "28:10:10";
    $timeArr = array_reverse(explode(":", $time));
    $seconds = 0;
    foreach ($timeArr as $key => $value)
    {
        if ($key > 2) break;
        $seconds += pow(60, $key) * $value;
    }
    $seconds;
    print secondsToTime($seconds);

OUTPUT 1:04:10:10