php计算持续时长(将秒转换成天时秒)

php计算持续时长

 

 

<?php


/**
 * 计算持续时长
 *
 * @param int $second 秒数
 * @return string $duration 5天10小时43分钟40秒
 */
function secondTime($seconds=0){
    $duration = '';

    $seconds  = (int) $seconds;
    if ($seconds <= 0) {
        return $duration.'0秒';
    }

    list($day, $hour, $minute, $second) = explode(' ', gmstrftime('%j %H %M %S', $seconds));

    $day -= 1;
    if ($day > 0) {
        $duration .= (int) $day.'天';
    }
    if ($hour > 0) {
        $duration .= (int) $hour.'小时';
    }
    if ($minute > 0) {
        $duration .= (int) $minute.'分钟';
    }
    if ($second > 0) {
        $duration .= (int) $second.'秒';
    }

    return $duration;
}

 

posted @ 2020-05-12 16:14  MargoHu  阅读(959)  评论(0编辑  收藏  举报