Home >>JavaScript Date Object Methods >JavaScript setUTCHours() Method

JavaScript setUTCHours() Method

JavaScript setUTCHours() Method

JavaScript setUTCHours() method is used to set the hour of a given input date object according to the universal time (UTC). It can also be used to set the minutes, seconds and milliseconds. UTC is the Universal Coordinated Time that is the time set by the World Time Standard.

Syntax:
Date.setUTCHours(hour, min, sec, millisec)

Parameter Values

Parameter Description
hour This is a required parameter. It defines an integer representing the hour.
min This is an optional parameter. It defines an integer representing the minutes.
sec This is an optional parameter. It defines an integer representing the seconds.
millisec This is an optional parameter. It defines an integer representing the milliseconds.

Browser Support

Method Chrome Edge Firefox Safari Opera
setUTCHours() Yes Yes Yes Yes Yes
Here is an example of JavaScript setUTCHours() method:
<html>
<body>
<p>Click the button to see the Output.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() 
{
  var d = new Date();
  d.setUTCHours(13);
  document.getElementById("demo").innerHTML = d;
}
</script>
</body>
</html>
Output:

Click the button to see the Output.

Example 2:
<html>
<body>
<p>Click the button to see the Output.</p>
<button onclick="myFunction1()">Try it</button>
<p id="demo1"></p>
<script>
function myFunction1() 
{
  var d = new Date();
  d.setUTCHours(13, 35, 5);
  document.getElementById("demo1").innerHTML = d;
}
</script>
</body>
</html>
Output:

Click the button to see the Output.


No Sidebar ads