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.
<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>
Prev | Home | Next |
Date.getHours() | Up | Date.getMinutes() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |