Time()是以秒为单位的——有以毫秒为单位的吗?


当前回答

用这个: 函数get_millis () { List ($usec, $sec) =爆炸(' ',microtime()); 返回(int) ((int) $sec * 1000 + ((float) $usec * 1000)); }

Bye

其他回答

我个人使用这个:

public static function formatMicrotimestamp(DateTimeInterface $dateTime): int
{
    return (int) substr($dateTime->format('Uu'), 0, 13);
}

简单的回答是:

$milliseconds = floor(microtime(true) * 1000);

用这个: 函数get_millis () { List ($usec, $sec) =爆炸(' ',microtime()); 返回(int) ((int) $sec * 1000 + ((float) $usec * 1000)); }

Bye

$the_date_time = new DateTime($date_string);
$the_date_time_in_ms = ($the_date_time->format('U') * 1000) +
    ($the_date_time->format('u') / 1000);

PHP 5.2.2 <

$d = new DateTime();
echo $d->format("Y-m-d H:i:s.u"); // u : Microseconds

PHP 7.0.0 < 7.1

$d = new DateTime();
echo $d->format("Y-m-d H:i:s.v"); // v : Milliseconds