PHP 将秒数(4490)转换成天时分秒(34:02:02)

将秒数转换成时分秒,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

转载:http://blog.sina.com.cn/s/blog_6ad5907b0101dex3.html

猜你喜欢

转载自blog.csdn.net/haibo0668/article/details/82658288