This article mainly introduces the method of calculating duration based on seconds in PHP. It has a certain reference value. Now I share it with you. Friends in need can refer to it
/** * 计算持续时长 * * @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; }
The above is the entire content of this article , I hope it will be helpful to everyone’s learning. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
php method to calculate the relative path of two files
The above is the detailed content of PHP method based on seconds PHP duration. For more information, please follow other related articles on the PHP Chinese website!