Key takeaways:
The getTime() method return the numeric value representing the time of a specific date object in milliseconds since January 1, 1970, 00:00:00 UTC (the Unix Epoch).
The method is called on a Date object like this: dateObj.getTime().
The getTime() does not take any parameters and returns the time in milliseconds.
We often encounter situations where we need to work with time and dates. The getTime() method provides a straightforward solution for working with date objects in JavaScript. Let’s learn this method together and see how it can enhance our time manipulation tasks.
What is getTime()?
The getTime() method is a part of the JavaScript Date object and is used to retrieve the numeric value corresponding to the time for a specific date object. This value is expressed in milliseconds since January 1, 1970, 00:00:00 UTC (the Unix Epoch). By using getTime(), we can easily perform calculations involving dates and times, such as finding the difference between two dates or setting specific date thresholds.
Syntax
We declare the getTime() method as shown below: