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

JavaScript setUTCSeconds() Method

JavaScript setUTCSeconds() Method

JavaScript setUTCSeconds() method is used to set the seconds of a given input date object according to the universal time (UTC). It can also be used to set the milliseconds.

Syntax:
Date.setUTCSeconds(sec, millisec)

Parameter Values

Parameter Description
sec This is a required 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
setUTCSeconds() Yes Yes Yes Yes Yes
Here is an example of JavaScript setUTCSeconds() 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.setUTCSeconds(46);
  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.setUTCSeconds(53, 888);
  var s = d.getUTCSeconds();
  var ms = d.getUTCMilliseconds();
  var x = document.getElementById("demo1");
  x.innerHTML = s + ":" + ms;
}
</script>
</body>
</html>
Output:

Click the button to see the Output.


No Sidebar ads