首页 > Web开发 > 详细

PHP 秒数 转时分秒 函数

时间:2017-05-07 13:48:16      阅读:300      评论:0      收藏:0      [点我收藏+]
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 秒数 转时分秒 函数

原文:http://www.cnblogs.com/wqy415/p/6820538.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!