在php中如果我們要獲取毫秒就必須通過microtime()再進行轉換,下面我來給各位朋友舉幾個實例,希望對大家會有所幫助。
問題不怕弱智…啥都記,代碼如下:
- function getmicrotime()
- {
- list($usec, $sec) = explode(" ",microtime());
- return ((float)$usec + (float)$sec);
- }
其實就是處理了一下microtime()這個函數,microtime()這個函數的返回值是這種形式:0.06261400 1303715872
空格后面為當前的時間戳,空格前面是當前的精確時間,例,計算頁面執行時間函數,代碼如下:
- <?php
- /**
- * Simple function to replicate PHP 5 behaviour
- */
- function microtime_float()
- {
- list($usec, $sec) = explode(" ", microtime());
- return ((float)$usec + (float)$sec);
- }
- $time_start = microtime_float();
- // Sleep for a while
- usleep(100);
- $time_end = microtime_float();
- $time = $time_end - $time_start;
- echo "Did nothing in $time secondsn";
- ?>
新聞熱點
疑難解答