问题
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.
Make a cookie expire in 30 seconds
How to set a cookie to expire in 1 hour in Javascript?
回答1:
JavaScript uses milliseconds to represent epoch time.
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.
Reference -
- MDN - Date
回答2:
Because it's given to you in milliseconds.
Seconds * 1000 = Milliseconds
回答3:
getTime
The value returned by the getTime method is the number of milliseconds since 1 January 1970 00:00:00 UTC
回答4:
It's using milliseconds. That's why we need to multiply the seconds with 1000 to get an equivalent value.
来源:https://stackoverflow.com/questions/19363506/why-we-multiply-seconds-with-1000-in-javascript-to-add-time