You can use the
DateTime class in PHP to format a date with fractional seconds. Here’s an example:
$date = new DateTime(); $microseconds = sprintf("%06d", $date->format("u")); $formatted_date = $date->format("Y-m-d H:i:s.$microseconds"); echo $formatted_date;
This code creates a new
DateTime object with the current date and time, formats the microseconds portion of the date to include leading zeros, and then formats the entire date string with the microseconds included. The output will look something like this:
Note that the number of decimal places in the fractional seconds portion of the date will depend on the precision of the system clock.