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:
const time: number = Date.now();
console.log(time); // Example output: 1647958987232
or:
const getCurrentTime = (): number => {
const date = new Date();
return date.getTime();
};
// Usage example:
const time: number = getCurrentTime();
console.log(time); // Example output: 1647959027055
The above solutions return the current time in milliseconds since Unix Epoch (January 1, 1970).