Home >>JavaScript Date Object Methods >JavaScript setMilliseconds() Method
JavaScript setMilliseconds() method is a Date method, which is used to set the Milliseconds of a given date on the basis of local time.
Syntax:Date.setMilliseconds(millisec)
Parameter | Description |
---|---|
millisec | It is Required. An integer between 0-999, representing the milliseconds |
Method | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
setMilliseconds() | Yes | Yes | Yes | Yes | Yes |
<html> <body> <button onclick="mysetMillisec()">click me</button> <p id="setSec"></p> <script> function mysetMillisec() { var x = new Date(); x.setMilliseconds(1010); var z = x.getMilliseconds(); document.getElementById("setSec").innerHTML = z; } </script> </body> </html>
<html> <body> <script> var milliSec1=new Date(); document.writeln("Current millisecond : "+milliSec1.getMilliseconds()+"<br>"); milliSec1.setMilliseconds(-1); document.writeln("Updated millisecond : "+milliSec1.getMilliseconds()); </script> </body> </html>