PHP根据秒计算持续时长


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

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

    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;
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM