Date setUTCMilliseconds() Method - Javascript Date

Javascript examples for Date:setUTCMilliseconds

Description

The setUTCMilliseconds() method sets the milliseconds from 0 to 999, according to universal time.

UTC time is the same as GMT time.

Syntax

date.setUTCMilliseconds(millisec);

Parameter Values

Parameter Description
millisec Required. An integer representing the milliseconds

millisec expected values are 0-999, but other values are allowed:

  • -1 sets the last millisecond of the previous second
  • 1000 sets the first millisecond of the next second

Return Value:

A Number, representing the number of milliseconds between the date object and midnight January 1 1970

The following code shows how to Set the milliseconds to 192, according to UTC time:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//from  ww w  .j  ava  2  s . co  m
    var d = new Date();
    d.setUTCMilliseconds(192);
    var n = d.getUTCMilliseconds();
    document.getElementById("demo").innerHTML = n;
}
</script>

</body>
</html>

Related Tutorials