How to Returns the minutes, according to universal time (from 0-59) in JavaScript ?
To return the minutes, according to universal time (from 0-59) in JavaScript, we can use the getUTCMinutes()
method. This method returns the minutes in the specified date according to universal time.
Here's an example:
const now = new Date();
const minutes = now.getUTCMinutes();
console.log(minutes); // Output: 0-59 (depending on the current time in UTC)
Another way to achieve the same result is by using the getMinutes()
method along with the getUTCMinutes()
method. The getMinutes()
method returns the minutes in the specified date according to the local time zone. By subtracting the local time zone offset from the local minutes, we can get the minutes in UTC.
Here's an example:
const now = new Date();
const minutes = now.getMinutes() - now.getTimezoneOffset();
console.log(minutes); // Output: 0-59 (depending on the current time in UTC)
Note that the getTimezoneOffset()
method returns the time zone offset in minutes between the local time zone and UTC. By subtracting this offset from the local minutes, we get the minutes in UTC.