Date.getMilliseconds() (Method)

Returns the milliseconds value of a date/time.

Availability:

ECMAScript edition - 2
JavaScript - 1.2
JScript - 3.0
Internet Explorer - 4.0
Netscape - 4.0
Property/method value type:Number primitive
JavaScript syntax:-myDate.getMilliseconds()

The milliseconds of the time value contained in the receiving object. The result will be an integer in the range 0 to 999 inclusive.

The value is computed according to local time coordinates.

In the example a timer is set up to trigger a function call every 1000 milliseconds. However, processing load may affect how accurately the timer is executed. By measuring the time on each call, we know that the millisecond value should be the same each time but you will probably observe a small and random perturbation in the value. You can compensate for this by making a small adjustment to the timer value to take this error into account. You will most likely need to reduce the value 1000 by a few milliseconds to get a more accurate timer.

Example code:

   <HTML>
   <HEAD></HEAD>
   <BODY>
   <DIV ID="RESULT">000</DIV>
   <SCRIPT>
   // Check the accuracy of a timer by printing the milliseconds
   setInterval("monitor()", 1000);
   myOldMSecs = 000;
   function monitor()
   {
   myDate  = new Date();
   myMsecs = myDate.getMilliseconds();
   myErr = myMsecs - myOldMSecs;
   document.all.RESULT.innerText = myMsecs + " (" + myErr + " milliseconds of error)";
   myOldMSecs = myMsecs;
   }
   </SCRIPT>
   </BODY>
   </HTML>

See also:Date.prototype, Date.setMilliseconds(), Date.setUTCMilliseconds()

Cross-references:

ECMA 262 edition 2 - section - 15.9.5.20

ECMA 262 edition 3 - section - 15.9.5.24