Javascript - Date setUTCMinutes() Method

The setUTCMinutes() method sets the minutes of a date object, according to UTC time.

Description

The setUTCMinutes() method sets the minutes of a date object, according to UTC time.

UTC time is the same as GMT time.

Syntax

Date.setUTCMinutes(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, according to UTC time:

Demo

//display the date after changing the minutes.
var d = new Date();
d.setUTCMinutes(17);//from w  w  w  .ja  va2s . c  o m
console.log(d);

//Set the date time to be 90 minutes ago, using UTC methods:
//display the date after setting the time to be 90 minutes ago.

var d = new Date();
d.setUTCMinutes(d.getUTCMinutes() - 90);
console.log(d);

Result