setUTCHours()
Date
instance method
JS Home <<
JS Reference <<
Date <<
setUTCHours()
Description
Sets the UTC hour of the day (0-23) for the specified date.
Syntax
Signature | Description |
---|---|
aDate.setUTCHours(hoursInt[, minutesInt | Sets the UTC 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 setUTCHours() method will try and set the date accordingly. |
Examples
The code below shows examples of the setUTCHours()
method of Date
.
// Create a Date instance for the current date and time.
var todaysDate = new Date();
alert(todaysDate);
// Set UTC hours.
todaysDate.setUTCHours(12);
alert(todaysDate + ' - UTC Hours set to 12');
// Set UTC hours, minutes and seconds.
todaysDate.setUTCHours(9,10,11);
alert(todaysDate + ' - UTC Hours, minutes and seconds set');
Related Tutorials
JavaScript Intermediate Tutorials - Lesson 2 - Dates and Times