在 Javascript 中减去日期会返回负数

发布于 2024-10-03 09:44:47 字数 365 浏览 0 评论 0原文

我正在使用 链接文本 中的 TimeTracker.js 来跟踪页面加载时间并将其放入 Google Analytics(分析)中。基本上它的作用是记录开始时间,一旦页面加载,它就会记录结束时间,然后减去。这些是使用 (new Date()).getTime() 记录的。

除了时间差在 0-100 毫秒之间的情况外,一切正常。这里我得到了一个巨大的负数,例如-17,183,398,582。有谁知道是什么原因造成的?它与 Javascript 处理日期减法的方式有关,还是与 Analytics 有关?

非常感谢任何帮助。谢谢

I am using the TimeTracker.js from link text to track Page Load times and put them in Google Analytics. Basically what it does is record a start time, and once the page loads it records a end time and then subtracts. These are recored using (new Date()).getTime().

Everything works fine except for instances where the time difference is between 0-100ms. Here I get a massive negative numbers such as -17,183,398,582. Does anyone know what is causing this? Is it got to do with the way Javascript is handling the date substraction or is it something to do with Analytics?

Any help much appreciated. Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼泪淡了忧伤 2024-10-10 09:44:47

只是猜测,但这个负数听起来可能与 Unix 纪元 时间相关联。示例:

var currentTime = new Date().getTime();

currentTime 将保存一个数字,例如 1289985468,表示“GMT:Wed,2010 年 11 月 17 日 09:17:48 GMT”。

也许您正在使用的代码中存在错误。

Just a guess, but that negative number sounds like it could be linked to Unix epoch time. Example:

var currentTime = new Date().getTime();

currentTime will hold a number such as 1289985468 which represents "GMT: Wed, 17 Nov 2010 09:17:48 GMT".

Perhaps there's a bug in that code you're using.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文