PHP 獲取時間毫秒時間及UTC

<?php

$a =  get_msectime();
$b = get_microtime_format($a*0.001);   

//返回當前的毫秒時間戳
    function get_msectime() {
        list($msec, $sec) = explode(' ', microtime());
        $msectime =  (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
        return $msectime;

     }

     /**
      *時間戳 轉   日期格式 : 精確到毫秒,x代表毫秒
      */
     function get_microtime_format($time)
     {
        if(strstr($time,'.')){
            sprintf("%01.3f",$time); //小數點。不足三位補0
            list($usec, $sec) = explode(".",$time);
            $sec = str_pad($sec,3,"0",STR_PAD_RIGHT); //不足3位。右邊補0
        }else{
            $usec = $time;
            $sec = "000";
        }
        $date = date("Y-m-d H:i:s.x T",$usec);
        return str_replace('x', $sec, $date);
     }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章