This method is used to set the hours for the supplied date according to local time.
This method is used to set the hours for the supplied date according to local time. If you do not supply the minutesVal and secondsVal and msVal arguments, JavaScript will use the values returned using the getUTCMinutes, getUTCSeconds and getMilliseconds methods. Also, if the supplied argument is outside the range expected, the setHours method will alter the other parameters accordingly (see example below).
myDate = new Date()
document.write(myDate +"<br>")
myDate.setHours(15, 100)
document.write(myDate)
Fri Jul 9 13:47:32 UTC+0100 1999
Fri Jul 9 16:40:32 UTC+0100 1999
This example uses the setHours 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 minutesVal supplied is 100 which causes the hourVal value to be incremented by 1.
This is calculated thus:
100 - 60 (maximum expected value for minutes) = 40 (this increments hoursVal by one).
The result of this calculation (40) is then used for the minutesVal
parameter.