首页 > 代码库 > PHP 秒数 转时分秒 函数

PHP 秒数 转时分秒 函数

function secondsToHour($seconds){
    if(intval($seconds) < 60)
        $tt ="00时00分".sprintf("%02d",intval($seconds%60));
    if(intval($seconds) >=60){
        $h =sprintf("%02d",intval($seconds/60));
        $s =sprintf("%02d",intval($seconds%60));
        if($s == 60){
            $s = sprintf("%02d",0);
            ++$h;
        }
        $t = "00";
        if($h == 60){
            $h = sprintf("%02d",0);
            ++$t;
        }
        if($t){
            $t  = sprintf("%02d",$t);
        }
        $tt= $t."时".$h."分".$s.‘秒‘;
    }
    if(intval($seconds)>=60*60){
        $t= sprintf("%02d",intval($seconds/3600));
        $h =sprintf("%02d",intval($seconds/60)-$t*60);
        $s =sprintf("%02d",intval($seconds%60));
        if($s == 60){
            $s = sprintf("%02d",0);
            ++$h;
        }
        if($h == 60){
            $h = sprintf("%02d",0);
            ++$t;
        }
        if($t){
            $t  = sprintf("%02d",$t);
        }
        $tt= $t."时".$h."分".$s.‘秒‘;
    }
   return  $seconds>0?$tt:‘00时00分00秒‘;
}

 

PHP 秒数 转时分秒 函数