Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript setUTCHours() Method

JavaScript setUTCHours() Method

Date Object Reference JavaScript Date object

Example

Set the hours field to 15 according to Universal Time (UTC):

var d = new Date();

d.setUTCHours(15);

d Output according to local time:

Try it »


Definition and Usage

The setUTCHours() method is used to set the hours (0 - 23) according to Universal Time (UTC).

This method can be used to set the minutes, seconds, and milliseconds.

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

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


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the setUTCHours() method.


Syntax

Date

.setUTCHours(

hour

,

min

,

sec

,

millisec

)

Parameter Values

Parameters Description
hour Required. The value to set for the hours field of dateObject.

This parameter is an integer between 0 and 23:

  • -1 is the last hour of the previous day.
  • 24 is the first hour of tomorrow.
  • | | *min* | Optional. The value to set for the minutes field of date Object.

    This parameter is an integer between 0 and 59:

    | | *sec* | Optional. The value to set for the seconds field of date Object.

    This parameter is an integer between 0 and 59:

    | | *millisec* | Optional. The value to set for the milliseconds field of date Object.

    This parameter is an integer between 1 and 999:

    |

    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 according to Universal Time (UTC):

    var d = new Date();

    d.setUTCHours(15,35,1);

    d Output the result according to local time:

    Try it »

    Example

    Set the time to 48 hours earlier according to Universal Time (UTC):

    var d = new Date();

    d.setUTCHours(d.getUTCHours()-48);

    d Output the result according to local time:

    Try it »


    Date Object Reference JavaScript Date object