2012-05-15 40 views
0

這裏是我用來獲取當前時間和微秒的代碼,添加微秒時間在PHP

$time=date("Y-m-d\TH:i:s") . substr((string)microtime(), 1, 8); 

我需要在microsecond.Is可以添加一些值來改變$時間的價值添加微秒的時間? 實際上我需要的是需要創建一個模擬器,在這裏我需要檢查一秒鐘內發生多少次執行,並查找執行所需的微秒數。

+1

有一個格式字符「U」爲微秒 – Pavel

+0

沒錯,@Pavel是正確的...在PHP 5.2.2 – Ray

+0

加入微秒如何添加微秒值到一個虛擬的??是可能的? – Shin

回答

0

您可以爲像這樣的舊版本構建回退函數。 (這僅適用於當前的時間)

function udate($format, $utimestamp = null){ 
       if(is_null($utimestamp)){ 
        $utimestamp = microtime(true); 
        $timestamp = floor($utimestamp); 
        $milliseconds = round(($utimestamp - $timestamp) * 1000000); 
        return date(str_replace("u",$milliseconds,$format), $timestamp); 
       }else 
        return date($format, $utimestamp); 
      } 

echo udate('Y-m-d H:i:s.u');