Javascript Date setUTCSeconds(seconds)

Introduction

Javascript Date setUTCSeconds(seconds) sets the UTC date's seconds. Setting the seconds to a number greater than 59 also increments the minutes.

dateObj.setUTCSeconds(secondsValue[, msValue])

Parameters

  • secondsValue - An integer between 0 and 59, representing the seconds.
  • msValue - Optional. A number between 0 and 999, representing the milliseconds.

Return value

The number of milliseconds between 1 January 1970 00:00:00 UTC and the updated date.

If a parameter is outside of the expected range, setUTCSeconds() updates the date accordingly.

For example, if you use 100 for secondsValue, the minutes stored in the Date object will be incremented by 1, and 40 will be used for seconds.

var d = new Date();
console.log(d);/*from ww w. jav a2s.  co  m*/
d.setUTCSeconds(20);
console.log(d);

Set both the seconds and milliseconds, according to UTC:

var d = new Date();
d.setUTCSeconds(35, 825);//from   ww w .  ja  va2  s . co  m
var s = d.getUTCSeconds();
var ms = d.getUTCMilliseconds();
console.log(s + ":" + ms);



PreviousNext

Related