user3934058
user3934058

Reputation:

Date() returns a year in future instead of correct year

date('Y-m-d H:i:s','1345453380000'); should return 2012-08-20 09:03:00 but instead it returns 44605-09-21 02:00:00

I understand the time difference of one day may be due to me not specifically setting timezone in the conversion, but 38k years in the future is a bit off, where am I doing it wrong? Is it the trailing zeros?

I appreciate any pointers... (BTW That timestamp is how certain apps deliver them, I did not craft it myself)

When I getdate() that same timestamp the same issue happens, so I don't think my code is wrong, rather something is problematic with the trailing 0's... But even if I use the from human to timestamp converted, with epoch converter, I get wrong results.

ONLY if I remove ALL zeros it seems to return a proper date. Why?

Note again, the timestamp is how it comes from an online "diary" App, and Epoch converter IS able to read it! (https://www.epochconverter.com/)

Upvotes: 0

Views: 101

Answers (2)

user2103237
user2103237

Reputation: 69

date('Y-m-d H:i:s',(1345453380000/1000));

Above code converts milliseconds to seconds.

Upvotes: 1

Martin Dimitrov
Martin Dimitrov

Reputation: 1304

What is happening here is that the timestamp is in milliseconds, but PHP expects seconds. Epoch converter works fine with both seconds and milliseconds. What you have to do is call date('Y-m-d H:i:s', ($timestamp/1000));

Look at this demo.

Upvotes: 3

Related Questions