PHP擷取目前時間的毫秒數

來源:互聯網
上載者:User
1 second = 1000 millisecond = 1000,000 microsecond = 1000,000,000 nanosecond

php的毫秒是沒有預設函數的,但提供了一個microtime()函數,該函數返回包含兩個元素,一個是秒數,一個是小數表示的毫秒數,藉助此函數,可以很容易定義一個返回毫秒數的函數,例如:

    /*         * 擷取時間差,毫秒級         */        function get_subtraction()        {                $t1 = microtime(true);                $t2 = microtime(true);                return (($t2-$1)*1000).'ms';        }
    /*         * microsecond 微秒     millisecond 毫秒         *返回時間戳記的毫秒數部分         */        function get_millisecond()        {                list($usec, $sec) = explode(" ", microtime());                $msec=round($usec*1000);                return $msec;                         }                 /*         *         *返回字串的毫秒數時間戳記         */        function get_total_millisecond()        {                $time = explode (" ", microtime () );                 $time = $time [1] . ($time [0] * 1000);                 $time2 = explode ( ".", $time );                 $time = $time2 [0];                return $time;        }            /*         *         *返回當前 Unix 時間戳記和微秒數(用秒的小數表示)浮點數表示,常用來計算程式碼片段執行時間         */                 function microtime_float()        {            list($usec, $sec) = explode(" ", microtime());            return ((float)$usec + (float)$sec);        }
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.