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