How do I convert milliseconds to a date in PHP?

DDD
Release: 2024-11-02 12:05:03
Original
419 people have browsed it

How do I convert milliseconds to a date in PHP?

Convert Milliseconds to Date in PHP

In PHP, you can convert milliseconds since the Unix epoch to a date string using the date() function. However, it's essential to consider the correct value of milliseconds for the targeted date.

You mentioned that your code is converting "1227643821310" milliseconds to "2-12-2008" in d-m-Y format. However, after checking, it turns out that the provided milliseconds correspond to "25-11-2008" when converted.

To ensure accuracy, remember that milliseconds represent the number of milliseconds since the Unix epoch (January 1, 1970 UTC). In the example provided, the milliseconds you specified translate to November 25, 2008 at 08:10:21 UTC, which aligns with the result "25-11-2008."

To convert milliseconds to a date in PHP, you can use the following code:

<code class="php">$mil = 1227643821310;
$seconds = $mil / 1000;
echo date("d-m-Y", $seconds);</code>
Copy after login

This code will print "25-11-2008," which is the correct date for the provided milliseconds.

The above is the detailed content of How do I convert milliseconds to a date 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
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!