温馨提示×

PHP获取毫秒时间戳的方法有哪些

PHP
小亿
83
2024-03-02 17:32:26
栏目: 编程语言

  1. 使用microtime函数:
$time = microtime(true) * 1000;
echo $time;
  1. 使用DateTime类:
$dateTime = new DateTime();
$milliseconds = $dateTime->getTimestamp() * 1000 + round($dateTime->format('u') / 1000);
echo $milliseconds;
  1. 使用gmdate函数:
$milliseconds = gmdate('U') * 1000 + round(gmdate('u') / 1000);
echo $milliseconds;

0