JavaScript » Date » setUTCSeconds

object.setUTCSeconds(secondsVal [, msVal])
an integer (0 thru 59) representing the seconds.
this value is an integer (1 thru 999) that represents the milliseconds.

This method is used to set the seconds for the specified date according to universal time.

This method is used to set the seconds for the supplied date according to universal 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 setUTCSeconds method will alter the other parameters of the date object accordingly (see example below).


myDate = new Date()
document.write(myDate +"<br>")
Fri Jul 9 13:30:20 UTC+0100 1999
Fri Jul 9 13:31:30 UTC+0100 1999

This example uses the setUTCSeconds 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.