Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current unix time in milliseconds in javascript

Hi this is incredibly simple i cant believe im asking this.

I have tried the following:

Moment.now()
Date.now()
new Date().valueOf()

And various other tricks found in other stack overflow questions

They all give me the time in microseconds.

e.g

1543409290654

which is 09/10/50878 @ 10:57am (UTC)

Im aware i could divide by 1000 but surely there is an api in javascript to get the unix timestamp in milliseconds.

Ive have seen this in chrome and react native

EDIT:

So i realise my stupidity i was putting the unix timestamp into a website that renders it as an ISO date but it was expecting seconds which is why i thought my dates were coming in as milliseconds

like image 368
Luke De Feo Avatar asked Sep 17 '25 15:09

Luke De Feo


1 Answers

Date.now() returns the number of milliseconds since midnight January 1, 1970

like image 109
lostbard Avatar answered Sep 19 '25 06:09

lostbard