JavaScript getMilliseconds() | Get the Milliseconds (0-999)

The JavaScript getMilliseconds() method is used to get the milliseconds (0-999). For example:

HTML with JavaScript Code
<!DOCTYPE html>
<html>
<body>
   
   <p id="xyz"></p>

   <script>
      const d = new Date();
      let ms = d.getMilliseconds();
      document.getElementById("xyz").innerHTML = ms;
   </script>

</body>
</html>
Output

JavaScript getMilliseconds() Syntax

The syntax of getMilliseconds() method in JavaScript is:

x.getMilliseconds()

where x must be an object of the Date() constructor.

The getMilliseconds() method returns a number from 0 to 999 which will be the milliseconds of the local time.

Please note: To display date in format dd-mm-yyyy, refer to its separate example.

Please note: To display time in format hh:mm:ss, refer to its separate example.

Please note: To display time in format hh:mm:ss AM/PM, refer to its separate example.

JavaScript Online Test


« Previous Tutorial Next Tutorial »