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

3
  • 4
    I'm guessing the JS time stamp is in miliseconds and PHP in seconds. What functions are you using?
    – barell
    Mar 10, 2014 at 22:33
  • the PHP time is strtotime and the Jquery time is $.now() @Barell Mar 10, 2014 at 22:36
  • I suggest you to read documentation before you will ask a question next time.
    – barell
    Mar 10, 2014 at 22:38

4 Answers 4

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.

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).

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.

0

To get a matching PHP time try.

<?php echo microtime(); ?>
2
  • microtime() returns microseconds not milliseconds.
    – barell
    Mar 11, 2014 at 0:28
  • round(microtime(true) * 1000) returns timestamp as milliseconds
    – barell
    Mar 11, 2014 at 0:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.