Reputation: 4386
How is the running time of the virtual machine calculated vs. how system time is calculated? I know I can get the current running time of the AVM by calling:
getTimer();
And I can get the current unix system time by doing:
new Date().getTime();
I know that the Timer class and Event.ENTER_FRAME event each come with their ups and downs, but I figured the 2 values I was comparing should stay consistently relative to each other. Here's how I'm testing 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 don't understand why those numbers would slowly get out of sync. Using that code, I've found, at least on my computer, that the values grow apart from each other by about 3 milliseconds per minute, with the value coming from system time being the higher value and the value coming from AVM time being the lower.
Can anyone offer me an explanation what those are calculated on and why there would be that small, yet growing gap in their values as time passes?
Upvotes: 4
Views: 3602
Reputation: 1541
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);
}
Upvotes: 0
Reputation: 312
On my computer (Win 7 64-Bit), sometimes getTimer
runs slower than Date.getTime()
(system time), but sometimes getTimer()
runs faster. The difference can range from -0.57ms/sec to 0.1ms/sec.
The result is independent of running in browser or Flash standalone player.
Upvotes: 0
Reputation: 2555
On my system the same code gives no difference between getTimer()
and getTime()
after ~10 mins the difference is always between 0 and 1 ms.
Maybe it's an issue of you system or the specific to the player you're running?
I'm running flash player 11 on Win 7 x64.
Upvotes: 1