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.

Syntax

Date.setMilliseconds(millisec)

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

Example

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

<!DOCTYPE html>

<html>

<body>

<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();

        d.setMilliseconds(192);

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

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

    }

</script>

</body>

</html>

Output1

setmillisecond 1.jpg

Output2

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

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.