Date setMilliseconds() Method - Javascript Date

Javascript examples for Date:setMilliseconds

Description

The setMilliseconds() method sets the milliseconds of a date object.

Syntax

date.setMilliseconds(millisec)

Parameter Values

Parameter Description
millisec Required. An integer representing the milliseconds

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
  • 1001 sets the second 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:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

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

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

<script>
function myFunction() {/*ww  w.j av a  2s  .c om*/
    var d = new Date();
    d.setMilliseconds(192);
    var n = d.getMilliseconds();
    document.getElementById("demo").innerHTML = n;
}
</script>

</body>
</html>

Related Tutorials