English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript setHours() Method

 JavaScript Date Object

Using setHours()The method sets the hour for the specified date object based on local time.

This method can also be used to set minutes, seconds, and milliseconds.

Syntax:

date.setHours(hours, minutes, seconds, millisec)
var d = new Date();
d.setHours(18);
Test and see‹/›

If not specified minutes, seconds And millisec Parameters, use the values returned by getMinutes(), getSeconds(), and getMilliseconds() methods.

Browser Compatibility

All browsers fully support the setHours() method:

Method
setHours()IsIsIsIsIs

Parameter Value

ParameterDescription
hours(Required) 0 to23The integer between represents hours.
If the provided value is greater than23The integer between represents hours.
minutes(Optional) 0 to59The integer between represents minutes.
If the provided value is greater than59The integer between represents minutes.
seconds(Optional) 0 to59The integer between represents minutes.
If the provided value is greater than59The integer between represents seconds.
If specifiedsecondsIf the parameter is specified, it must also be specifiedminutesParameters.
millisec(Optional) 0 to999The number between represents milliseconds.
If the provided value is greater than999, the date and time will be increased by an additional millisecond.
If specifiedmillisecIf the parameter is specified, it must also be specifiedMinuteAndSecondParameters.

Technical Details

Return Value:1970 Year1Month1Milliseconds between the date and time '00:00:00 UTC' and the update date
JavaScript Version:ECMAScript 1

 JavaScript Date Object