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:

date.getUTCMinutes();

Returns:

  • An integer representing the minutes of the hour (from 0 to 59).

Example 1: Getting UTC Minutes for a Specific Date

const date = new Date('2024-10-22T15:30:00Z'); // October 22, 2024, at 15:30:00 UTC const utcMinutes = date.getUTCMinutes(); console.log(utcMinutes);

Output:

30

Explanation:

  • The Date object represents October 22, 2024, at 15:30:00 UTC. The getUTCMinutes() method returns 30, which corresponds to the minutes in the given time.

Example 2: Getting UTC Minutes for a Local Time

const localDate = new Date('2024-10-22T12:00:00'); // October 22, 2024, at 12:00 PM local time const utcMinutesFromLocal = localDate.getUTCMinutes(); console.log(utcMinutesFromLocal);

Output:

0

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() returns 0 because there are no additional minutes past the hour.

Example 3: Getting UTC Minutes for a Date Near Midnight

const nearMidnightLocal = new Date('2024-10-22T23:59:59'); // October 22, 2024, at 23:59:59 local time const utcMinutesNearMidnight = nearMidnightLocal.getUTCMinutes(); console.log(utcMinutesNearMidnight);

Output:

59

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() returns 59, representing the last minute before midnight in UTC.

Example 4: Getting UTC Minutes for a Date Object Created with UTC

const utcDate = new Date(Date.UTC(2024, 9, 22, 15, 30, 0)); // October 22, 2024, at 15:30:00 UTC const utcMinutesCreated = utcDate.getUTCMinutes(); console.log(utcMinutesCreated);

Output:

30

Explanation:

  • The Date.UTC() method creates a date object for October 22, 2024, at 15:30:00 in UTC. The getUTCMinutes() method returns 30, confirming the correct minutes in the UTC time.

Summary:

  • date.getUTCMinutes() returns the minutes of a Date 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.