Question

i get a epoch time returned from a webservice wich is about 3 years off in PHP but fine in javascript and the epochconverter.com

JS:

alert('book '+ new Date(1285565357893)); // returns a time this morning 27 sep 2010, Correct!

PHP:

echo strftime('%x', 1285565357893); // returns a date in 2013, Wrong !

Timezone is set to: Europe/Amsterdam

What am i doing wrong here ?

Was it helpful?

Solution

OK, some simple time basics for you.

Javascript Date class... when you pass a numeric value to the constructor, this is the number of milliseconds since the Unix Epoch (January 1 1970 00:00:00 GMT)

PHP date is measured as the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).

Convert from milliseconds to seconds in PHP by dividing by 1000.

echo strftime('%x', floor(1285565357893/1000));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top