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

JavaScript setUTCMilliseconds() Method

JavaScript setUTCMilliseconds() Method

JavaScript setUTCMilliseconds() method is used to set the milliseconds according to the universal time (UTC). As a result it return an integer having value between 0 to 999.

Syntax:
Date.setUTCMilliseconds(millisec)

Parameter Values

Parameter Description
millisec This is a required parameter. It defines an integer representing the milliseconds.

Browser Support

Method Chrome Edge Firefox Safari Opera
setUTCMilliseconds() Yes Yes Yes Yes Yes
Here is an example of JavaScript setUTCMilliseconds() 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.setUTCMilliseconds(100);
  var n = d.getUTCMilliseconds();
  document.getElementById("demo").innerHTML = n;
}
</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.setUTCMilliseconds(150);
  var n = d.getUTCMilliseconds();
  document.getElementById("demo1").innerHTML = n;
}
</script>
</body>
</html>
Output:

Click the button to see the Output.


No Sidebar ads