Easy Tutorial
❮ Prop Datetime Type Prop Win Screenleft ❯

JavaScript setUTCHours() Method

JavaScript Date Object

Example

Set the hour field to 15 based on UTC:

d output in local time:

var d = new Date();
d.setUTCHours(15);
document.write(d);

Definition and Usage

The setUTCHours() method is used to set the hour (0 - 23) based on UTC.

This method can also set the minutes, seconds, and milliseconds.

Tip: Coordinated Universal Time (UTC), also known as Universal Coordinated Time, World Standard Time, and International Coordinated Time.

Note: UTC time is the same as GMT (Greenwich Mean Time).


Browser Support

All major browsers support the setUTCHours() method.


Syntax

Parameter Values

Parameter Description
hour Required. The value to set for the hour field of the dateObject. This parameter is an integer between 0 and 23: -1 is the last hour of the previous day. <br> 24 is the first hour of the next day.
min Optional. The value to set for the minute field of the dateObject. This parameter is an integer between 0 and 59: -1 is the last minute of the previous hour. <br> 60 is the first minute of the next hour.
sec Optional. The value to set for the second field of the dateObject. This parameter is an integer between 0 and 59: -1 is the last second of the previous minute. <br> 60 is the first second of the next minute.
millisec Optional. The value to set for the millisecond field of the dateObject. This parameter is an integer between 1 and 999: -1 is the last millisecond of the previous second. <br> 1000 is the first millisecond of the next second.

Return Value

Type Description
Number The number of milliseconds from January 1, 1970, to the adjusted date.

Technical Details

| JavaScript Version: | 1.3 | | --- | --- |


More Examples

Example

Set the time to 15:35:01 based on UTC:

d output in local time:

Example

Set the time to 48 hours ago based on UTC:

d output in local time:


JavaScript Date Object

❮ Prop Datetime Type Prop Win Screenleft ❯