Home > Article > Backend Development > 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>
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!