美文网首页Android
Android Record Elapsed Time

Android Record Elapsed Time

作者: JaedenKil | 来源:发表于2018-10-23 16:37 被阅读1次

    Two possible methods:

    SystemClock.elapsedRealtime()
    
    System.currentTimeMillis()
    

    Details:

    long startTime = SystemClock.elapsedRealtime();
    long endTime = SystemClock.elapsedRealtime();
    double elapsedSeconds = (endTime - startTime) / 1000.0;
    
    long startTime = System.currentTimeMillis();
    long endTime = System.currentTimeMillis();
    double durationTime = (endTime - startTime) / 1000.0;
    

    They may look like the same, but according to this:
    SystemClock Document says about elapsedRealtime(): This clock is guaranteed to be monotonic, and continues to tick even when the CPU is in power saving modes, so is the recommend basis for general purpose interval timing.
    And System.currentTimeMillis(): is the standard "wall" clock (time and date) expressing milliseconds since the epoch. The wall clock can be set by the user or the phone network, so the time may jump backwards or forwards unpredictably. This clock should only be used when correspondence with real-world dates and times is important, such as in a calendar or alarm clock application. Interval or elapsed time measurements should use a different clock.

    相关文章

      网友评论

        本文标题:Android Record Elapsed Time

        本文链接:https://www.haomeiwen.com/subject/ddyazftx.html