METHOD:
Date::setSeconds
object.setSeconds(secondsVal
[, msVal])
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).
The available parameters are as follows:
secondsVal - an integer (0 thru 59) representing
the seconds.
msVal - this value is an integer (1 thru 999)
that represents the milliseconds.
The following code 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.
Code:
myDate = new Date()
document.write(myDate +"<br>")
myDate.setSeconds(90)
document.write(myDate)
Output:
Fri Jul 9 13:30:20 UTC+0100 1999
Fri Jul 9 13:31:30 UTC+0100 1999 |