Why don't the PHP and Javascript timestamps match?

If i do

alert(new Date(1313690400000))

returns: Thu Aug 18 2011 13:00:00 GMT-0500 (CDT)

however php

echo date('Ymd H:i:s', 1313690400000);

returns: 1951-12-14 05:50:24

+6
source share
3 answers

JavaScript uses milliseconds as a timestamp, while PHP uses seconds. As a result, you get different dates, since it is disabled 1000 times.

So, remove the three zeros from the PHP side:

 echo date('Ymd H:i:s', 1313690400); 
+18
source

PHP's date and time functions use the number of seconds since an era, while Javascript uses the number of milliseconds. In your php func:

 echo date('Ym-d', 1313690400000 / 1000); 
+6
source

Javascript Date is the milliseconds since the Epoch era, while the PHP date uses the unix timestamp, which is in seconds.

So, to get the same date in php, divide by 1000 first

+6
source

Source: https://habr.com/ru/post/895367/


All Articles