How to measure elapsed time

后端 未结 5 1831
暖寄归人
暖寄归人 2020-11-29 22:09

I have a 10 and 20 question game. I need to count how much time is passed when a user finishes the game.

Timer T=new Timer();
T.scheduleAtFixedRate(new Timer         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 22:55

    When the game starts:

    long tStart = System.currentTimeMillis();
    

    When the game ends:

    long tEnd = System.currentTimeMillis();
    long tDelta = tEnd - tStart;
    double elapsedSeconds = tDelta / 1000.0;
    

提交回复
热议问题