Javascript Reference - JavaScript setMinutes() Method








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

This method can also be used to set the seconds and milliseconds.

Browser Support

setMinutes() Yes Yes Yes Yes Yes

Syntax

dateObject.setMinutes(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 object and midnight January 1 1970.

Example


var myDate = new Date();
      
myDate.setMinutes(12);
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:


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

The code above is rendered as follows: