Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个函数,它使用当前时间戳来获取一些数据和 sql 表,但是一些数据加倍,因为它们在同一秒内运行两次。
我需要用包括毫秒在内的时间戳来获取它们。
我用
$timestamp = date_format($date, 'Y-m-d H:i:s');
有没有类似的东西:
$serverTime = date_format($date, 'Y-m-d H:i:s:milisecs');
我试图在 $timestamp 中包含 microtime() 的毫秒,但直到现在还没有运气。
$t = microtime(); echo $t;
这对我有用,我得到毫秒和当前时间戳。你的问题在哪里?
使用DateTime->format()。
<?php $date = new DateTime(); echo $date->format('Y-m-d H:i:s.u'); ?>