PHP 7.1中DateTime::__construct()是否支援毫秒
有資訊顯示在7.1版中,DateTime::__construct()已經可以支援毫秒。並且專門強調:
This means that naive comparisons of two newly created instances will now more likely return FALSE instead of TRUE: new DateTime() == new DateTime()
#可是,在我的程式碼中,毫秒部分總是“000000”,這個是什麼問題呢:
1 2 3 4 5 6 7 | <code><?php
for ( $i = 0; $i < 10000; ++ $i ) {
$date = new DateTime();
file_put_contents ( './msec.log' , "$i:\t" . $date ->format( 's.u' ) . PHP_EOL, FILE_APPEND);
}</code>
|
輸出:
1 2 3 4 5 6 7 8 9 10 11 | <code>0: 51.000000
1: 51.000000
2: 51.000000
……
4999: 51.000000
5000: 51.000000
5001: 51.000000
……
9997: 51.000000
9998: 51.000000
9999: 51.000000</code>
|