Getting different unix timestamps in php and javascript (server time is wrong)

basically im trying to get php equivalent time()in javascript

here is the code:

var jstamp =  Math.round(new Date().getTime() / 1000) ;
var pstamp =  <?php echo time(); ?>;

console.log( 'jstamp is : '+ jstamp);
console.log( 'pstamp is : '+ pstamp);

here is the result:

jstamp is : 13939 45587
pstamp is : 13939 33954

they differ from each other in the last 5 digits

echo date_default_timezone_get();
echo date('Y-m-d H:i:s');

result:

UTC2014-03-04 11:57:13

Server time seems wrong but shouldn't be wrong for php and js? that still I should not get the same result in both of them?

+4
source share
1 answer

This will probably be the time zone of your server. You can manually install it in PHP: http://php.net/manual/de/function.date-default-timezone-set.php

0
source

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


All Articles