Difference between Date.getTime () and getTimer

How is the virtual machine’s uptime calculated compared to how the system time is calculated? I know that I can get the current AVM runtime by calling:

getTimer();

And I can get the current unix system time by doing:

new Date().getTime();

I know that each class Timer and Event.ENTER_FRAME have their ups and downs, but I decided that the 2 values ​​that I compared should remain unchanged relative to each other. This is how I test it:

 private var _appRunTime:int; private var _appStartTime:int; private var _systemTime:int; private var _systemCurrentTime:int; //called at application launch protected function application1_creationCompleteHandler(event:FlexEvent):void { _systemTime = new Date().getTime(); _appStartTime = getTimer(); } //called on button click to see values protected function button1_clickHandler(event:MouseEvent):void { _systemCurrentTime = new Date().getTime(); _appRunTime = getTimer(); trace(_systemCurrentTime - _systemTime, _appRunTime - _appStartTime); } 

I do not understand why these numbers slowly fail. Using this code, I found, at least on my computer, that the values ​​grow separately by about 3 milliseconds per minute, with the value coming from the system time being a higher value, and the value coming from the AVM time, is below.

Can someone offer me an explanation of what they are designed for and why there is such a small but growing gap in their values ​​over time?

+4
source share
3 answers

On my system, the same code makes no difference between getTimer() and getTime() after ~ 10 minutes, the difference is always between 0 and 1 ms.

Maybe this is the problem of your system or the specific player with whom you work?

I am running flash player 11 on Win 7 x64.

+1
source

On my computer (Win 7 64-Bit), sometimes getTimer is slower than Date.getTime() (system time), but sometimes getTimer() is faster. The difference can be from -0.57 ms / s to 0.1 ms / s.

The result is independent of the browser or the standalone Flash player.

0
source

It will help you ...

 public static function getDaysBetweenDates(date1:Date,date2:Date):int { var one_day:Number = 1000 * 60 * 60 * 24 var date1_ms:Number = date1.getTime(); var date2_ms:Number = date2.getTime(); var difference_ms:Number = Math.abs(date1_ms - date2_ms) return Math.round(difference_ms/one_day); } 
0
source

All Articles