有信息显示在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