在PHP中,可以使用microtime()
函数来获取当前的时间戳,包括毫秒级精度。示例代码如下:
// 获取当前时间戳,精确到毫秒
function getMillisecondsTimestamp() {
list($msec, $sec) = explode(' ', microtime());
return (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
}
$timestamp = getMillisecondsTimestamp();
echo $timestamp;
上面的代码中,microtime()
函数返回当前时间的秒数和微秒数,通过计算得到毫秒级的时间戳。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:php怎么获取毫秒级时间戳