How to use setMilliseconds in JavaScript

In this article, I will explain use of setMilliseconds() method in JavaScript date object.
  • 1543

JavaScript setMilliseconds() method

  • setMilliseconds() method of date method  is used to set the milliseconds for a specified date according to local time.
  • setMilliseconds() method sets the milliseconds of a date object.

  • setMilliseconds() method is supported in all major browsers.



  • Mili : Mili is optional parameter. A number is representing the milliseconds and it's value between 0 and 999.


In the following example show to setMilliseconds() method set the milliseconds to 192.

<!DOCTYPE html>



<h3 style="color:Teal ">JavaScript setMilliseconds() Method Example</h3>

<p id="demo">Click for display the millisecond of a date time, after setting the millisecond.</p>

<button onclick="myFunction()">Try it</button>

<script type="text/javascript">

    function myFunction() {

        var d = new Date();


        var x = document.getElementById("demo");

        x.innerHTML ="After setting of Milliseconds time is : "+ d.getMilliseconds();






setmillisecond 1.jpg


setmillisecond 2.jpg

You may also want to read these related articles here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here


More Articles

© 2020 DotNetHeaven. All rights reserved.