Home > Article > Backend Development > Why is my PHP code converting milliseconds to an incorrect date?
php: Convert Milliseconds to Date Accuracy
When converting a string representing milliseconds since the Unix epoch to a date in d-m-Y format, it's crucial to ensure the accuracy of the conversion. Despite the code provided, the result obtained may not match the expected outcome due to a misunderstanding of the given string.
The code:
<code class="php">$mil = 1227643821310; $seconds = $mil / 1000; echo date("d-m-Y", $seconds);</code>
correctly converts the milliseconds to seconds, but the original value, "1227643821310," corresponds to 25-11-2008, not 02-12-2008. This explains the discrepancy in the output.
The above is the detailed content of Why is my PHP code converting milliseconds to an incorrect date?. For more information, please follow other related articles on the PHP Chinese website!