Retrieve a Date Format of m-d-Y H:i:s.u from Milliseconds
Problem:
Obtaining a formatted date with microseconds from a UNIX timestamp provided in milliseconds has been an ongoing challenge. Upon attempting to do so, the output consistently yields 000000, even though the expected result should display microseconds.
Solution:
To resolve this issue, the correct input format is U.u, as demonstrated below:
$now = DateTime::createFromFormat('U.u', microtime(true)); echo $now->format("m-d-Y H:i:s.u");
Output:
This approach produces the desired output:
04-13-2015 05:56:22.082300
PHP Date Format Interpretation:
Additional Notes:
The above is the detailed content of How to Retrieve Date Format with Microseconds from Millisecond Timestamp?. For more information, please follow other related articles on the PHP Chinese website!