Date.getMilliseconds() (Method)

Returns the milliseconds value of a date/time.


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:

   <DIV ID="RESULT">000</DIV>
   // 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;

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


ECMA 262 edition 2 - section -

ECMA 262 edition 3 - section -