Introduction to the use of the setHours () method in JavaScript, javascriptsethours
The javascript Date. setHours () method sets the hour on the specified Date according to the local time.
Syntax
Date.setHours(hoursValue[, minutesValue[, secondsValue[, msValue]]])
Note: parameters in brackets are optional.
The following is the detailed information about the parameters:
- HoursValue: an integer between 0 and 23, representing the hour
- MinutesValue: an integer between 0 and 59, representing minutes
- SecondsValue: an integer between 0 and 59, representing the second. If you specify the secondsValue parameter, you must also specify minutesValue
- MsValue: a number between 0 and 999, representing milliseconds. If the msValue parameter is specified, minutesValue and secondsValue must also be specified.
If the minutesValue, secondsValue, and msValue parameters are not specified, use the getUTCMinutes, getUTCSeconds, and getMilliseconds methods to return values.
Return Value:
Example:
This produces the following results:
Thu Aug 28 02:30:00 UTC+0530 2008