简体   繁体   English

jQuery时间戳和PHP时间戳之间的区别?

[英]difference between Jquery timestamp and php timestamp?

is there a difference between Jquery's timestamp and php/sql's time stamp? Jquery的时间戳和php / sql的时间戳之间有区别吗?

I've got two timestamps-- the PHP one is: 我有两个时间戳,PHP是:

1394488721

while the Jquery one is: 而Jquery之一是:

139449051952

They're very similar--but obviously the jquery one is a bit longer. 它们非常相似-但显然jquery更长一些。

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 我正在尝试使用这两者来同步$ .load函数,该函数每次运行cron作业时都会从数据库加载一些信息

Timestamps in jQuery (as returned by $.now , which defers to Date.prototype.getTime ) JavaScript are expressed in milliseconds. jQuery中的时间戳(由$.now返回,它对应于Date.prototype.getTime )JavaScript以毫秒表示。 In PHP, (using time et al) they are in seconds. 在PHP中(使用time等),它们以秒为单位。

JavaScript's Date object is based on milliseconds, whereas PHP's (as generated by time() ) is based in seconds. JavaScript的Date对象基于毫秒,而PHP的Date对象(由time()生成)基于秒。

Also, there may be timezone differences to account for, I believe JavaScript will use the current timezone for the computer by default (eg 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). 另外,可能存在时区差异,我相信JavaScript默认会使用计算机的当前时区(例如“浏览器的时区”),而PHP可能基于PHP配置文件中定义的时区(或用户的时区(如果您以某种方式在域模型上进行设置和使用)。

Multiply the PHP timestamp by 1000 to create a new Javascript timestamp based on it: 将PHP时间戳乘以1000以基于它创建一个新的Javascript时间戳:

JS Timestamp := PHP Timestamp * 1000

This JS Timestamp is in milliseconds, so you can compare with other JS Date() values. 该JS时间戳以毫秒为单位,因此您可以与其他JS Date()值进行比较。

要获得匹配的PHP时间,请尝试。

<?php echo microtime(); ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM