2 Replies Latest reply on Jan 16, 2009 8:45 PM by John Hall

    Calls to Date.getTime() return same value over time??

    borfgordon
      Hi,
      I have a method in a class that is called repeatedly in the following example. Basically every 10 calls to the function I capture the difference in time and then reset the "lastTS" variable to the current time. Between each call to this method there is a fair amount of work being done (files written to disk, logging etc)

      What I am seeing is that occasionally, randomly, the difference (diff var) is equaling 0 (zero) meaning that the timestamp caputured 10 iterations ago is equal to the current timestamp? How is this possible when I am doing various things as described above between calls to this method (logging, writing to disk etc)?


      private var lastTS:Number = new Date().getTime();
      private var timesCalled:Number =0;

      public function myfunc():void {
      var now:Number = new Date().getTime();
      timesCalled++;

      if((timesCalled % 10) == 0) {
      var diff:Number = now - lastTS;
      if (diff == 0) {
      // WHAT??? this should not happen!!
      }
      lastTS = now;
      }

      }