This method is used to set the seconds for the specified date according to local time.
This method is used to set the seconds for the supplied date according to local time. If you do not supply the msVal argument, JavaScript will use the value returned using the getMilliseconds method. Also, if the supplied argument is outside the range expected, the setSeconds method will alter the other parameters of the date object accordingly (see example below).
myDate = new Date()
document.write(myDate +"<br>")
myDate.setSeconds(90)
document.write(myDate)
Fri Jul 9 13:30:20 UTC+0100 1999
Fri Jul 9 13:31:30 UTC+0100 1999
This example uses the setSeconds method to change the value of the myDate object and also demonstrates how this method will adjust the other parameters if a value is supplied that exceeds the expected range. In this case the secondsVal supplied is 90 which causes the minutes to be incremented by 1.
This is calculated thus:
90 - 60 (maximum expected value for seconds) = 30 (this increments the minutes by one).
The result of this calculation (30) is then used for the secondsVal
parameter.