秒与00:00:00转换

    /**
     * 00:00:00=>秒
     */
    public function stringToSec($time)
    {
        $arr = explode(':', $time);
        $time_h = $arr[0]*3600;
        $time_i = $arr[1]*60;
        $time_s = $arr[2];
        $time = $time_h+$time_i+$time_s;

        return $time;
    }


    /**
     * 秒=>00:00:00
     */
    public function secToString($time)
    {

        $hour = floor($time/3600);//小时数
        $min = floor(($time%3600)/60);//分钟数
        $sec = floor($time%3600%60);//秒数

        if($sec<10) {
            $sec = '0'.$sec;
        }
        if($min<10) {
            $min = '0'.$min;
        }
        if($hour<10) {
            $hour = '0'.$hour;
        }
        return $hour . ":" . $min . ":" . $sec;
    }

 

posted @ 2022-09-13 10:35  cmooc  阅读(71)  评论(0编辑  收藏  举报