Date().getTime() JavaScript convert to php?



我有这个jquery函数来获取日期差异。

function distance(date) {
return (new Date().getTime() - date.getTime());
}

我试图将这个新的日期((转换为php:

function distance(date) {
return (<?php echo time(); ?> - date.getTime());
}

这样我就可以获取服务器日期而不是用户日期。 但这是错误的,因为时间差异变成了 49 年。 有什么想法吗?

在 php 中time()返回以秒为单位的时间。(在 unix 时间(

而在Javascript中,它在毫秒内返回。

您的解决方案是以毫秒为单位转换 php 时间。

function distance(date) {
return (<?php echo time()*1000; ?> - date.getTime());
}

最新更新