Linux timestamp for PHP

I have the following timestamp:

1342259667654

which when converted from http://www.epochconverter.com/ gives:

Assuming that this timestamp is in milliseconds:
GMT: Sat, 14 Jul 2012 09:54:27 GMT
Your time zone: 14. juli 2012 11:54:27 GMT+2

And this is the right time, but when using:

echo date("Y-m-d H:i:s", 1342259667654);

I get the following date:

1904-07-24 10:22:47

How can I get the exact date of this stamp with PHP?

+5
source share
3 answers

Your timestamp should be divided by 1000:

echo date("Y-m-d H:i:s", 1342259667654/1000);
+6
source
$timestamp = 1342259667; 
$dt = new DateTime("@$timestamp");  // convert UNIX timestamp to PHP DateTime
echo $dt->format('Y-m-d H:i:s');

You can also do it this way.

+2
source

The value is 1342259667654actually in milliseconds, and the PHP function date()cannot process the value of miliseconds. Hence a strange conclusion.

0
source

All Articles