Home > Backend Development > PHP Tutorial > Why Does My PHP Code Show the Wrong Date When Converting Milliseconds?

Why Does My PHP Code Show the Wrong Date When Converting Milliseconds?

DDD
Release: 2024-10-31 07:46:30
Original
679 people have browsed it

Why Does My PHP Code Show the Wrong Date When Converting Milliseconds?

PHP: Converting Milliseconds to Date - Issue Explained

In your code, you correctly convert milliseconds to seconds by dividing by 1000. However, the resulting timestamp does not correspond to the expected date of "2-12-2008" due to a misunderstanding.

Specifically, the millisecond timestamp of 1227643821310 represents November 25th, 2008, which is the date your code correctly displays. The expected date of "2-12-2008" corresponds to a different timestamp value.

Corrected Code:

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

The above is the detailed content of Why Does My PHP Code Show the Wrong Date When Converting Milliseconds?. 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