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

Mary-Kate Olsen
Release: 2024-11-01 08:15:02
Original
753 people have browsed it

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>
Copy after login

Output:

25-11-2008
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!