The setSeconds() method sets the seconds of a date object.
The setSeconds() method sets the seconds of a date object.
This method can also be used to set the milliseconds.
Date.setSeconds(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:
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: //display the date-time after changing the seconds. var d = new Date(); d.setSeconds(35);//from w w w .j av a 2 s.c om console.log(d); //Set both the seconds and milliseconds: //display seconds and milliseconds after changing both of them. d.setSeconds(35, 825); var s = d.getSeconds(); var ms = d.getMilliseconds(); console.log( s + ":" + ms);