The getUTCMinutes()
method in JavaScript is a part of the Date
object and is used to get the minutes (0-59) for a given date object, in the UTC time zone. This can be useful for getting the minutes in a specific time zone, or for working with dates and times in a consistent time zone.
Here’s an example of how to use getUTCMinutes()
to get the current minutes in UTC time:
let date = new Date();
let minutes = date.getUTCMinutes();
console.log(minutes); // Outputs the current minutes in UTC time
You can also pass a date object as an argument to getUTCMinutes()
to get the minutes for a specific date in UTC time:
let date = new Date(2022, 0, 1, 11, 30, 0); // January 1, 2022 at 11:30:00 (local time)
let minutes = date.getUTCMinutes();
console.log(minutes); // Outputs 30
Note that the getUTCMinutes()
method returns the minutes as a number between 0 and 59, with 0 representing no minutes and 59 representing 59 minutes.
In addition to getting the minutes, you can also use the setUTCMinutes()
method to set the minutes for a date object in UTC time. Here’s an example of how to use it:
let date = new Date();
date.setUTCMinutes(45); // Set the minutes to 45
console.log(date); // Outputs the current date and time with the minutes set to 45 in UTC time
Leave a Reply