System.currentTimeMillis () is not working correctly

I need stopWatch and I used http://www.goldb.org/stopwatchjava.html

This did not work, so I tried to write a value every 1000 ms:

stopWatch.start();
HandlerScrollBar.postDelayed(TtScroll,  1000);

private Runnable TtScroll = new Runnable() {
    public void run() {
        long time = stopWatch.getElapsedTime();
        HandlerScrollBar.postDelayed(TtScroll,(long) 1000);
        Log.d(TAG, Long.toString(time));            
    }
};

I can see the time value every second in CatLog, and this is the result:

enter image description here

The real time is max + 5ms, but in the column it is at least +3 seconds! How is this possible? Same thing with

new Date().getTime().

Is there any StopWatch class that will pass this test as expected?

Thanks.

+1
source share
2 answers

, , System.nanoTime(). System.currentTimeMillis(), , .

nanoTime - , currentTimeMillis - . . , ; .

nanoTime , - . nanoTime(), .

. javadoc:

long startTime = System.nanoTime(); 

//... ...

long estimatedTime = System.nanoTime() - startTime;
+3

. System.currentTimeMillis(). , Log.d(), logcat Log.e(). , -?

0

All Articles