Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

1 Answer
karthikeya Boyini

The Date object is a data type built into the JavaScript language. Date objects are created with the new Date( ) as shown below.

Once a Date object is created, a number of methods allow you to operate on it. Most methods simply allow you to get and set the year, month, day, hour, minute, second, and millisecond fields of the object, using either local time or UTC (universal, or GMT) time.

The getMilliseconds() function of the Date object returns the milliseconds of its current date.

Syntax

Its syntax is as follows

dateObj.getMilliseconds();

Example

Live Demo

<html>
   <head>
      <title>JavaScript Example</title>
   </head>
   <body>
      <script type="text/javascript">
         var dateObj = new Date('September 26, 89 12:4:25:96');
         document.write(dateObj.getMilliseconds());
      </script>
   </body>
</html>

Output

96

Example

Incase if you haven’t mentioned the milliseconds while creating the date object this function returns 0.

Live Demo

<html>
   <head>
      <title>JavaScript Example</title>
   </head>
   <body>
      <script type="text/javascript">
         var dateObj = new Date('september 26, 89 04:50:12');
         document.write(dateObj.getMilliseconds());
      </script>
   </body>
</html>

Output

0

Example

In the same way if you haven’t passed anything while creating the date object (to the constructor) this function returns the Current milliseconds.

Live Demo

<html>
   <head>
      <title>JavaScript Example</title>
   </head>
   <body>
      <script type="text/javascript">
         var dateObj = new Date();
         document.write("Current milliseconds: "+dateObj.getMilliseconds());
      </script>
   </body>
</html>

Output

Current milliseconds: 504

Example

The range of milliseconds in JavaScript is from 0 to 999 if you use value out of this range this function returns 0.

Live Demo

<html>
   <head>
      <title>JavaScript Example</title>
      </head>
   <body>
      <script type="text/javascript">
         var dateObj = new Date('september 26, 89 04:50:12:1035');
         document.write("Current milliseconds: "+dateObj.getMilliseconds());
      </script>
   </body>
</html>

Output

Current milliseconds: 0

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.