PHP根据秒计算持续时长
程序员文章站
2022-04-12 12:26:33
/** * 计算持续时长 * * @param int $second 秒数 * @return string $duration 5天10小时43分钟40秒 */ function second2duration($seconds) { $duration = ''; $seconds = (in... ......
/** * 计算持续时长 * * @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; }