PHP ミリ秒タイムスタンプ取得方法【初心者向け】
- microtime関数を利用する。
$time = microtime(true) * 1000;
echo $time;
- DateTimeクラスを使用します。
$dateTime = new DateTime();
$milliseconds = $dateTime->getTimestamp() * 1000 + round($dateTime->format('u') / 1000);
echo $milliseconds;
- gmdate関数を使用する:
$milliseconds = gmdate('U') * 1000 + round(gmdate('u') / 1000);
echo $milliseconds;