setHours()
Date
instance method
JS Home <<
JS Reference <<
Date <<
setHours()
Description
Sets the locale specific hour of the day (0-23) for the specified date.
Syntax
Signature | Description |
---|---|
aDate.setHours( hoursInt [, minutesInt | Sets the locale specific hour of the day (0-23) for the specified date. |
Parameters
Parameter | Description |
---|---|
hoursInt | An integer in the range 0-23. |
minutesInt | An integer in the range 0-59.
|
secondsInt | An integer in the range 0-59.
|
millisecondsInt | An integer in the range 0-999.
|
For specified values outside the ranges above the setHours() method will try and set the date accordingly. |
Examples
The code below shows examples of the setHours()
method of Date
.
// Create a Date instance for the current date and time.
var todaysDate = new Date();
alert(todaysDate);
// Set hours.
todaysDate.setHours(12);
alert(todaysDate + ' - Hours set to 12');
// Set hours, minutes and seconds.
todaysDate.setHours(9,10,11);
alert(todaysDate + ' - Hours, minutes and seconds set');
Related Tutorials
JavaScript Intermediate Tutorials - Lesson 2 - Dates and Times