$dateTime 不传值取当前时间
/**
* @param mixed $dateTime 任意有效时间格式
*
* @return int
* @throws \Exception
*/
function getMillisecond($dateTime = null): int
{
$microTime = $dateTime === null ? microtime(true) : (new \DateTime($dateTime))->getTimestamp() + microtime(true) - time();
return (int)($microTime * 1000);
}
示例:
var_dump(getMillisecond3()); // 1689221068283
var_dump(getMillisecond3('2023-7-13 11:51:02')); // 1689220262283
var_dump(getMillisecond3('10 September 2023')); // 1694275200283
var_dump(getMillisecond3('now')); // 1689221068283
标签:13,dump,getMillisecond3,int,dateTime,毫秒,var,PHP
From: https://www.cnblogs.com/buyucoder/p/17550117.html