Home > Article > Backend Development > How to Convert Milliseconds to a \"d-m-Y\" Date Format in PHP?
php: Convert Milliseconds to Date in the Format Needed
You are trying to convert a string representing a date in milliseconds since the Unix epoch to a date in the format d-m-Y. You are getting an unexpected result.
The issue is that the given milliseconds (1227643821310) do not represent the date "02-12-2008."
Instead, the given milliseconds represent the date "25-11-2008," which matches your output.
Correct Code:
The following code converts the milliseconds correctly to the expected format:
<code class="php">$mil = 1227643821310; $seconds = $mil / 1000; echo date("d-m-Y", $seconds);</code>
Output:
25-11-2008
The above is the detailed content of How to Convert Milliseconds to a \"d-m-Y\" Date Format in PHP?. For more information, please follow other related articles on the PHP Chinese website!