How to use new Date().getTime() method In Javascript
This method also returns the number of milliseconds since January 1, 1970, 00:00:00 UTC. It is an instance method of the Date object and is equivalent to calling the valueOf() method.
Syntax:
let timestamp = new Date().getTime();
Example 2: In this example, the new Date().getTime()
method is used to create a new Date
object and retrieve its timestamp in milliseconds. The timestamp
variable will hold the current timestamp, and it will be logged to the console.
const timestamp = new Date().getTime();
console.log(timestamp);
Output
1704968973447
How to get the timestamp in JavaScript ?
In JavaScript, a timestamp is a numeric representation of the current time. It is a unique identifier that marks the exact moment when an event occurred or when a certain action was performed. This timestamp is useful in various applications such as logging, debugging, or measuring time intervals. In this article, we will explore different approaches to getting a timestamp in JavaScript.
Below are the approaches used to get the timestamp in JavaScript:
Table of Content
- Using Date.now() method
- Using new Date().getTime() method
- Using new Date().valueOf() method
- Using +new Date() method: