有資訊顯示在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”,這個是什麼問題呢:
<?php
for ($i = 0; $i < 10000; ++$i) {
$date = new DateTime();
// if ($date->format('u') != '000000') {
file_put_contents('./msec.log', "$i:\t" . $date->format('s.u') . PHP_EOL, FILE_APPEND);
// }
}
輸出:
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