getTime() Method

The getTime() method in JavaScript is used to return the number of milliseconds(0–999).

Example: This example describes the getTime() method for retrieving the number of milliseconds from the date object.

JavaScript




let d = new Date();
console.log(d.getTime());


Output

1690865918886

JavaScript Get Date Methods

JavaScript Date Object allows us to get and set the date values.

In this article, we will know how to get the various date methods from the date object in Javascript. There are various methods that retrieve the date in JavaScript. The date values can get like years, months, days, hours, minutes, seconds, and milliseconds from a Date Object.

The following is the list of the date method to retrieve the various dates from the Date object in Javascript.

Methods:

  • getDate(): It is used to get the day as a number (1-31).
  • getFullYear(): It is used to get the year.
  • getHours(): It is used to get the hour (0-23).
  • getMilliseconds(): It is used to get the milliseconds (0-999).
  • getMinutes(): It is used to get the minutes (0-59).
  • getMonth(): It is used to get the month (0-11).
  • getSeconds(): It is used to get the seconds (0-59).
  • getTime(): It used to return the number of milliseconds since 1 January 1970.
  • getDay(): It is used to get the weekday as a number (0-6).
  • date.now(): It is used to return the number of milliseconds elapsed since January 1, 1970, 00:00:00 UTC.

We will implement the different date methods & understand their usage through the examples.

Similar Reads

getHours() Method

The getHours() method in JavaScript is used to return the hours of a date as a number (0-23)....

getDate() Method

...

getMonth() Method

The getDate() method in JavaScript is used to return the day of a date as a number (1-31)....

getFullYear() Method

...

getTime() Method

The getMonth() method in JavaScript is used to return the month of a date as a number (0-11)....

getSeconds() Method

...