当前位置 : 主页 > 网络编程 > PHP >

PHP把秒转换成天数,小时数和分钟

来源:互联网 收集:自由互联 发布时间:2021-06-30
function secsToStr($secs) { if($secs=86400){$days=floor($secs/86400);$secs=$secs%86400;$r=$days.' day';if($days1){$r.='s';}if($secs0){$r.=', ';}} if($secs=3600){$hours=floor($secs/3600);$secs=$secs%3600;$r.=$hours.' hour';if($hours1){$r.='s
function secsToStr($secs) {
    if($secs>=86400){$days=floor($secs/86400);$secs=$secs%86400;$r=$days.' day';if($days<>1){$r.='s';}if($secs>0){$r.=', ';}}
    if($secs>=3600){$hours=floor($secs/3600);$secs=$secs%3600;$r.=$hours.' hour';if($hours<>1){$r.='s';}if($secs>0){$r.=', ';}}
    if($secs>=60){$minutes=floor($secs/60);$secs=$secs%60;$r.=$minutes.' minute';if($minutes<>1){$r.='s';}if($secs>0){$r.=', ';}}
    $r.=$secs.' second';if($secs<>1){$r.='s';}
    return $r;
}

用法:
<?php
$seconds = "56789";
$output = secsToStr($seconds);
echo $output;
?>
网友评论