Home >>JavaScript Date Object Methods >JavaScript getMilliseconds() Method

JavaScript getMilliseconds() Method

JavaScript getMilliseconds() Method

JavaScript getMilliseconds() method is used to return the milliseconds of the given input date and time. It returns an integer value between 0 to 999.

Syntax:
Date.getMilliseconds()

Browser Support

Method Chrome Edge Firefox Safari Opera
getMilliseconds() Yes Yes Yes Yes Yes
Here is an example of JavaScript getMilliseconds() method:
<html>
<body>
<p>Click the button to see the Output.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() 
{
  var d = new Date();
  var n = d.getMilliseconds();
  document.getElementById("demo").innerHTML = n;
}
</script>
</body>
</html>
Output:

Click the button to see the Output.

Example 2:
<html>
<body>
<p>Click the button to see the Output.</p>
<button onclick="myFunction1()">Try it</button>
<p id="demo1"></p>
<script>
function myFunction1() 
{
  var d = new Date("June 10, 1857 15:15:00:515");
  var n = d.getMilliseconds();
  document.getElementById("demo1").innerHTML = n;
}
</script>
</body>
</html>
Output:

Click the button to see the Output.


No Sidebar ads