How to get milliseconds in Javascript
By FoxLearn 12/18/2024 6:45:55 AM 15
In JavaScript, you can get the current time in milliseconds using either `Date.now()` or the `getTime()` method of a `Date` object.
Both return the number of milliseconds since January 1, 1970, 00:00:00 UTC.
For example, Using Date.now()
:
let currentMilliseconds = Date.now(); console.log(currentMilliseconds);
For example, Using new Date()
and getTime()
:
let currentMilliseconds = new Date().getTime(); console.log(currentMilliseconds);
Both Date.now()
and getTime()
output the current time in milliseconds.
Categories
Popular Posts
11 Things You Didn't Know About Cloudflare
12/19/2024