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:
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
Output:
Explanation:
- The
Date
object represents October 22, 2024, at 15:30:45 (3:30:45 PM). ThegetMinutes()
method returns30
, indicating that it is the 30th minute of the hour.
Example 2: Getting Minutes for Midnight
Output:
Explanation:
- At midnight (00:00:00), there are no minutes past the hour, so
getMinutes()
returns0
.
Example 3: Getting Current Minutes
Output:
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 aDate
object, ranging from 0 to 59.- It is useful for extracting the minute information from a date and time object in JavaScript.