setUTCHours()  Date  instance method setterS2C Home  « Globals « Date « setUTCHours()

Description

Sets the UTC hour of the day (0-23) for the specified date.

Syntax

Signature Description
aDate.setUTCHours(hoursInt[, minutesInt [, secondsInt[, millisecondsInt]]])Sets the UTC hour of the day (0-23) for the specified date.

Parameters

Parameter Description
hoursIntAn integer in the range 0-23.
minutesIntAn integer in the range 0-59.
  • If minutesInt is not specified the value returned from the getUTCMinutes() method is used.
secondsIntAn integer in the range 0-59.
  • If secondsInt is not specified the value returned from the getUTCSeconds() method is used.
  • If secondsInt is specified you must also specify minutesInt.
millisecondsIntAn integer in the range 0-999.
  • If millisecondsInt not specified value returned from the getUTCMilliseconds() method is used.
  • If millisecondsInt is specified you must also specify minutesInt and secondsInt.
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');


Press the button below to action the above code:


Related Tutorials

JavaScript Intermediate Tutorials - Lesson 2 - Dates and Times

go to home page Homepage go to top of page Top