JavaScript date.getUTCMinutes() method
The date.getUTCMinutes()
method in JavaScript returns the minutes (from 0 to 59) of a specified Date
object according to Universal Coordinated Time (UTC). This method is useful for obtaining the minutes of a date without considering local time zone differences.
Syntax:
Returns:
- An integer representing the minutes of the hour (from 0 to 59).
Example 1: Getting UTC Minutes for a Specific Date
Output:
Explanation:
- The
Date
object represents October 22, 2024, at 15:30:00 UTC. ThegetUTCMinutes()
method returns30
, which corresponds to the minutes in the given time.
Example 2: Getting UTC Minutes for a Local Time
Output:
Explanation:
- If the local time is 12:00 PM, this will convert to a different UTC time depending on the local timezone. If your local timezone is UTC-3, then it would convert to 9:00 AM UTC. In this case,
getUTCMinutes()
returns0
because there are no additional minutes past the hour.
Example 3: Getting UTC Minutes for a Date Near Midnight
Output:
Explanation:
- If your local timezone is UTC-3, then the local time of 23:59:59 on October 22 will be 02:59:59 UTC on October 23. Therefore,
getUTCMinutes()
returns59
, representing the last minute before midnight in UTC.
Example 4: Getting UTC Minutes for a Date Object Created with UTC
Output:
Explanation:
- The
Date.UTC()
method creates a date object for October 22, 2024, at 15:30:00 in UTC. ThegetUTCMinutes()
method returns30
, confirming the correct minutes in the UTC time.
Summary:
date.getUTCMinutes()
returns the minutes of aDate
object in UTC, ranging from 0 to 59.- This method is helpful for working with time in a consistent manner, independent of local timezone adjustments.