How to get the current date and time with milliseconds accuracy in PHP

1 Answer

0 votes
$datetime = new DateTime();

$datetime->setTimezone(new DateTimeZone('UTC')); // Set timezone to UTC for accurate microseconds

echo $datetime->format('Y-m-d\TH:i:s.u\Z'); 

 
 
/*
run:
 
2024-12-06T10:07:02.912328Z
 
*/

 



answered Dec 6, 2024 by avibootz
...