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

 

相关文章:

  • 2022-12-23
  • 2021-09-12
  • 2022-12-23
  • 2021-09-19
  • 2021-09-17
  • 2022-12-23
  • 2021-10-28
  • 2021-09-17
猜你喜欢
  • 2022-12-23
  • 2022-02-24
  • 2022-12-23
  • 2022-12-23
  • 2022-02-22
相关资源
相似解决方案