1

is there a difference between Jquery's timestamp and php/sql's time stamp?

I've got two timestamps-- the PHP one is:

1394488721

while the Jquery one is:

139449051952

They're very similar--but obviously the jquery one is a bit longer.

I'm trying to use both these to sync an $.load function that loads some information from the DB every time a cron job is run

4 Answers4

4

Timestamps in jQuery (as returned by $.now, which defers to Date.prototype.getTime) JavaScript are expressed in milliseconds. In PHP, (using time et al) they are in seconds.

Jon
  • 428,835
  • 81
  • 738
  • 806
1

JavaScript's Date object is based on milliseconds, whereas PHP's (as generated by time()) is based in seconds.

Also, there may be timezone differences to account for, I believe JavaScript will use the current timezone for the computer by default (e.g. the "browser's timezone") while PHP's is likely based off of the timezone defined in the PHP configuration file (or the user's timezone, if you are setting and using that on a domain model somehow).

Sean Quinn
  • 2,131
  • 1
  • 18
  • 48
0

Multiply the PHP timestamp by 1000 to create a new Javascript timestamp based on it:

JS Timestamp := PHP Timestamp * 1000

This JS Timestamp is in milliseconds, so you can compare with other JS Date() values.

Niloct
  • 9,491
  • 3
  • 44
  • 57
0

To get a matching PHP time try.

<?php echo microtime(); ?>
Travis Petrie
  • 417
  • 2
  • 9