Home >Backend Development >PHP Tutorial >How to Convert Milliseconds to a \'d-m-Y\' Date Format in PHP?

How to Convert Milliseconds to a \'d-m-Y\' Date Format in PHP?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-01 08:15:02843browse

How to Convert Milliseconds to a

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn