php 自动把秒转换成分或者时
2019-12-31 本文已影响0人
Renew全栈工程师
/**
* 格式化秒自动到 分或者时
* @param int $second
* @return string
*/
function formatSecond($second = 0)
{
$unit = 0;
$result = $second;
$unitString = ['秒', '分', '时'];
while ($result > 59 && $unit < count($unitString) - 1) {
$unit++;
$result = floor($result / 60);
}
return $result . $unitString[$unit];
}