由网友(⊕シ狂野狩猎者)分享简介:我下面这个计数器。我有10和20个问题的游戏。我需要算多少时间过去了,当用户完成比赛。I have this counter below. I have a 10 and 20 questions game. I need to count how much time is passed when a user fi...
我下面这个计数器。我有10和20个问题的游戏。我需要算多少时间过去了,当用户完成比赛。
I have this counter below. I have a 10 and 20 questions game. I need to count how much time is passed when a user finish the game.
Timer T=new Timer();
T.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable()
{
public void run()
{
countdown.setText(""+count);
count++;
}
});
}
}, 1000, 1000);
我用它来停止计数器:
I use this to stop the counter:
T.cancel();
现在我需要两件事情。我需要的终值是一个双例如最后得分是:15,49秒。而第二件事是五言的方法来计算所经过的时间,并将其存储在一个变量。谢谢你。
Now I need two things. I need the final value to be a double, for example final score is: 15,49 seconds. And the second thing is of cource a way to count the elapsed time and store it in a variable. Thanks.
推荐答案
在游戏开始:
long tStart = System.currentTimeMillis();
在游戏结束:
long tEnd = System.currentTimeMillis();
long tDelta = tEnd - tStart;
double elapsedSeconds = tDelta / 1000.0;
相关推荐
最新文章