Javascript - Date setUTCSeconds() Method

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

Description

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

You can use this method to set the milliseconds.

UTC time is the same as GMT time.

Syntax

Date.setUTCSeconds(sec,millisec)

Parameter Values

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

For 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 seconds to 35, according to UTC time:

Demo

//display the date-time after changing the seconds.

var d = new Date();
d.setUTCSeconds(35);/*from ww  w.  j  av a 2  s.c  o  m*/
console.log(d);

//Set both the seconds and milliseconds, according to UTC:

//display seconds and milliseconds after changing both of them.
var d = new Date();
d.setUTCSeconds(35, 825);
var s = d.getUTCSeconds();
var ms = d.getUTCMilliseconds();
console.log( s + ":" + ms);

Result