为什么我们将秒数乘以1000以增加时间 [英] Why we multiply seconds with 1000 in Javascript to add time

查看:56
本文介绍了为什么我们将秒数乘以1000以增加时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理cookie,我在Stack Overflow上发现了一些已回答的问题.我在问题中看到答案的秒数乘以1000.我想知道getTime()返回的格式,这需要乘以1000.

I am working on cookies and I found some questions on Stack Overflow which have been answered. I see in the questions that the answers multiplied seconds by 1000. I want know what format getTime() returns, that would require multiplying by 1000.

使cookie在30秒内过期

如何设置Cookie用Javascript在1小时后过期?

推荐答案

JavaScript使用毫秒表示时间.

JavaScript uses milliseconds to represent epoch time.

Epoch时间是自1970年1月1日以来的秒数,并且有一秒内1000毫秒.因此,要获取自1970年1月1日以来的毫秒数,只需将值乘以1000.

Epoch time is the number of seconds since 01/01/1970 and there are 1000 milliseconds in one second. So to get the number of milliseconds since 01/01/1970 you just multiply the value by 1000.

参考-

这篇关于为什么我们将秒数乘以1000以增加时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆