计算时长 [英] Calculate Duration
问题描述
我有一个小机器人的问题,我有一个要求,有一个计时器来计算时间的特定活动是开到一定的按钮,在活动被点击,活动只是多长时间是开放的持续时间。虽然谷歌搜索周围,我发现TimerTask的,但这似乎只能虽然运行一个线程一定的时间间隔和doesent似乎非常适合从我小的Android体验
I have a small android problem, I have a requirement to have a timer to calculate the duration from the time a specific activity was open till a certain button in that activity is clicked, simply how long the activity was open. While googling around I found TimerTask but this seems to run a thread for a certain interval only though and doesent seem ideal for the job from my little Android experience
如何计算时间你知道吗? preferably在一个非常简单的方式
Any idea on how to calculate the duration? Preferably in a very simple manner
任何帮助是非常欢迎的。
Any help is very welcome
问候, MilindaD
Regards, MilindaD
推荐答案
只需使用<一个href="http://developer.android.com/reference/java/lang/System.html#currentTimeMillis%28%29"><$c$c>System.currentTimeMillis()$c$c>到当活动启动和停止拍摄的时间。例如:
Just use System.currentTimeMillis()
to capture the time when the activity starts and stops. E.g.:
long startTime = System.currentTimeMillis();
// wait for activity here
long endTime = System.currentTimeMillis();
long seconds = (endTime - startTime) / 1000;
这篇关于计算时长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!