EN
JavaScript - get current time in milliseconds
3 points
In this article, we would like to show you how to get the current time in milliseconds in JavaScript.
Quick solution:
xxxxxxxxxx
1
const time = Date.now();
2
3
console.log(time);
or:
xxxxxxxxxx
1
const getCurrentTime = () => {
2
const date = new Date();
3
return date.getTime();
4
};
5
6
7
// Usage example:
8
9
const time = getCurrentTime();
10
11
console.log(time);
The above solutions return the current time in milliseconds since Unix Epoch (January 1, 1970).