const timestamp = new Date().getTime();
console.log(timestamp);
Output
1643918032196
The getTime() function of the javascript Date() method returns the current timestamp. We can use this timestamp to verify when the specific task was performed. Below is an example.
# Code example 2
const result = new Date().getTime();
console.log(result);
In the above code snippet, we are using the 'new Date().getTime()' to get the current timestamp from a date.
We can also use the plus '+' operator of Javascript to get the timestamp. You just need to place the + operator before the Date() function and it will return the timetstamp.
Syntax
+ new Date()
# Code example 3
const timestamp = + new Date();
console.log(timestamp);
Output
1647761974083
const timestamp = new Date().valueOf();
console.log(timestamp);
0 Comments