Javascript - Date setMinutes() Method

The setMinutes() method sets the minutes of a date object.

Description

The setMinutes() method sets the minutes of a date object.

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

Syntax

Date.setMinutes(min,sec,millisec)

Parameter Values

Parameter Require Description
min Required. An integer representing the minutes.
sec Optional.An integer representing the seconds
millisec Optional.An integer representing the milliseconds

For the minute value, the expected values are 0-59, but other values are allowed:

  • -1 will result in the last minute of the previous hour
  • 60 will result in the first minute of the next hour

For the second value, the expected values are 0-59, but other values are allowed:

  • -1 will result in the last second of the previous minute
  • 60 will result in the first second of the next minute

For the millisec value, the expected values are 0-999, but other values are allowed:

  • -1 will result in the last millisecond of the previous second
  • 1000 will result in the first millisecond of the next second

Return

A Number, representing the number of milliseconds between the date object and midnight January 1 1970

Example

Set the minutes to 17:

Demo

//display the date after changing the minutes.

var d = new Date();
d.setMinutes(17);//from ww w.jav  a  2  s  . c  o m
console.log(d);

//Set the date time to be 90 minutes ago:
d.setMinutes(d.getMinutes() - 90);
console.log(d);

Result