1

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?

Community
  • 1
  • 1
Jitender
  • 7,593
  • 30
  • 104
  • 210

4 Answers4

9

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 -

Lix
  • 47,311
  • 12
  • 103
  • 131
3

Because it's given to you in milliseconds.

Seconds * 1000 = Milliseconds
Tyler
  • 11,272
  • 9
  • 65
  • 105
2

getTime

The value returned by the getTime method is the number of milliseconds since 1 January 1970 00:00:00 UTC

r043v
  • 1,859
  • 1
  • 15
  • 25
1

It's using milliseconds. That's why we need to multiply the seconds with 1000 to get an equivalent value.

opalenzuela
  • 3,139
  • 21
  • 41