Javascript Reference - JavaScript setUTCMinutes() Method








setUTCMinutes(minutes)
Sets the UTC date's minutes. Setting the minutes to a number greater than 59 also increments the hour.

UTC time is the same as GMT time.

Browser Support

setUTCMinutes() Yes Yes Yes Yes Yes

Syntax

dateObject.setUTCMinutes(min, sec, millisec);

Parameter Values

Parameter Description
min Required. An integer representing the minutes.
Expected values are 0-59, but other values are allowed:
-1 will be the last minute of the previous hour
60 will be the first minute of the next hour
sec Optional. An integer representing the seconds
Expected values are 0-59, but other values are allowed:
-1 will be the last second of the previous minute
60 will be the first second of the next minute
millisec Optional. An integer representing the milliseconds
Expected values are 0-999, but other values are allowed:
-1 will be the last millisecond of the previous second
1000 will be the first millisecond of the next second




Return Value

return a number representing the number of milliseconds between the date value and midnight January 1 1970.

Example


      var myDate = new Date();
      
      myDate.setUTCMinutes(21);
      console.log(myDate.toString());
      

The code above generates the following result.

Example 2

The following code sets the date time to be 10 minutes ago in UTC time


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--from   w  w  w .ja  v  a  2s .  com-->
    var d = new Date();
    d.setUTCMinutes(d.getUTCMinutes() - 10);
    document.getElementById("demo").innerHTML = d;
}
</script>
</body>
</html>

The code above is rendered as follows: