JavaScript setMinutes()Method

Date 对象参考手册JavaScript Date Object

Example

Set the minutes field to 17:

var d = new Date();
d.setMinutes(17);

dOutput:


Try it Yourself »

Definition and Usage

The setMinutes() method is used to set the minutes field of a specified time.

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


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the setMinutes() method


Syntax

Date.setMinutes(min,sec,millisec)

Parameter Values

Parameter Description
min Required. A numeric value representing the minutes,

Between 0 and 59, in local time (the same below):

  • -1 is the last minute of the previous hour
  • 60 is the first minute of the next hour
sec Optional. A numeric value representing the seconds,

Between 0 and 59. This parameter is not supported before ECMAScript standardization:

  • -1 is the last second of the previous minute
  • 60 is the first second of the next minute
millisec Optional. A numeric value representing the milliseconds,

Between 0 and 999. This parameter is not supported before ECMAScript standardization:

  • -1 is the last millisecond of the previous second
  • 1000 is the first millisecond of the next second

Return Value

Type Description
Number Returns the number of milliseconds from January 1, 1970 to the adjusted date. Before ECMAScript standardization, this method returned nothing.

Technical Details

JavaScript Version: 1.0


More Examples

Example

Set the date to 90 minutes ago:

var d = new Date();
d.setMinutes(d.getMinutes()-90);

dOutput:


Try it Yourself »


Date 对象参考手册JavaScript Date Object

Other Extensions