JavaScript Date setUTCHours() Method
- Previous Page setUTCFullYear()
- Next Page setUTCMilliseconds()
- Go Back to the Previous Level JavaScript Date Reference Manual
Definition and Usage
setUTCHours()
This method sets the hour of the date object based on UTC time.
This method can also be used to set minutes, seconds, and milliseconds.
Tip:Coordinated Universal Time (UTC) is the time set by the world time standard.
Note:UTC time is the same as GMT time (Greenwich Mean Time).
Instance
Example 1
Set the hour according to UTC time to 15:
var d = new Date(); d.setUTCHours(15);
Example 2
Set the time to UTC time 15:35:01:
var d = new Date(); d.setUTCHours(15, 35, 1);
Example 3
Use the UTC method to set the time 48 hours ago:
var d = new Date(); d.setUTCHours(d.getUTCHours() - 48);
Syntax
Date.setUTCHours(hour, min, sec, millisec)
Parameter Value
Parameter | Description |
---|---|
hour |
Required. Represents the integer hours. The expected value is 0-23, but other values are allowed:
|
min |
Optional. Represents the integer minutes. The expected value is 0-59, but other values are allowed:
|
sec |
Optional. Represents the integer seconds. The expected value is 0-59, but other values are allowed:
|
millisec |
Optional. Represents the integer milliseconds. The expected value is 0-999, but other values are allowed:
|
Technical Details
Return Value: | A number representing the milliseconds between the date object and midnight of January 1, 1970. |
---|---|
JavaScript Version: | ECMAScript 1 |
Browser Support
Method | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
setUTCHours() | Support | Support | Support | Support | Support |
Related Pages
Tutorial:JavaScript Date
Tutorial:JavaScript Date Format
Tutorial:JavaScript Date Setting Methods
- Previous Page setUTCFullYear()
- Next Page setUTCMilliseconds()
- Go Back to the Previous Level JavaScript Date Reference Manual