Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在研究 cookie,我在 Stack Overflow 上发现了一些已得到解答的问题。我在问题中看到答案将秒数乘以 1000。我想知道 getTime() 返回的格式,这需要乘以 1000。
使 cookie 在 30 秒内过期
如何在 Javascript 中设置 cookie 在 1 小时内过期?
JavaScript 使用毫秒来表示纪元时间。
纪元时间是自 1970 年 1 月 1 日以来的秒数,一秒有1000 毫秒。因此,要获得自 1970 年 1 月 1 日以来的毫秒数,只需将该值乘以 1000。
参考 -
因为它以毫秒为单位提供给您。
Seconds * 1000 = Milliseconds
获取时间
getTime 方法返回的值是自 1970 年 1 月 1 日 00:00:00 UTC 以来的毫秒数
它使用毫秒。这就是为什么我们需要将秒乘以 1000 以获得等效值。