JavaScript date.getMinutes() method


The date.getMinutes() method in JavaScript returns the minutes (from 0 to 59) of a specific Date object, according to local time.

Syntax:

date.getMinutes();

Returns:

  • A number between 0 and 59 that represents the minutes for the specified date.

Example 1: Getting Minutes for a Specific Date and Time

const date = new Date('2024-10-22T15:30:45'); // October 22, 2024, 15:30:45 (3:30:45 PM) const minutes = date.getMinutes(); console.log(minutes);

Output:

30

Explanation:

  • The Date object represents October 22, 2024, at 15:30:45 (3:30:45 PM). The getMinutes() method returns 30, indicating that it is the 30th minute of the hour.

Example 2: Getting Minutes for Midnight

const date = new Date('2024-10-22T00:00:00'); // Midnight on October 22, 2024 const minutes = date.getMinutes(); console.log(minutes);

Output:

0

Explanation:

  • At midnight (00:00:00), there are no minutes past the hour, so getMinutes() returns 0.

Example 3: Getting Current Minutes

const now = new Date(); // Current date and time const currentMinutes = now.getMinutes(); console.log(currentMinutes);

Output:

(Depends on the current minutes)

Explanation:

  • This retrieves the current minutes of the time according to the user's local time. For example, if the current time is 11:45 AM, the output will be 45.

Summary:

  • date.getMinutes() returns the minutes component of a Date object, ranging from 0 to 59.
  • It is useful for extracting the minute information from a date and time object in JavaScript.