The setUTCSeconds() method sets the seconds of a date object, according to UTC time time.
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.
Date.setUTCSeconds(sec,millisec)
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:
For the millisec value, the expected values are 0-999, but other values are allowed:
A Number, representing the number of milliseconds between the date object and midnight January 1 1970
Set the seconds to 35, according to UTC time:
//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);