gpt4 book ai didi

javascript - Date().getTime() JavaScript 转换为 php?

转载 作者:行者123 更新时间:2023-11-29 16:34:14 25 4
gpt4 key购买 nike

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

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

我尝试将这个新的 date() 转换为 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());
}

关于javascript - Date().getTime() JavaScript 转换为 php?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52938180/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com