【发布时间】:2015-06-02 06:24:13
【问题描述】:
我想在 android 中长时间使用倒数计时器...
目前,我正在使用此代码,但在几个小时后,比如 10 小时后,格式变为 10 : 650 :56 (hh:mm:ss)... 对于较短的时间,它可以完美运行...
private Runnable updateTimerMethod = new Runnable() {
public void run() {
timeInMillies = SystemClock.uptimeMillis() - startTime;
finalTime = timeSwap + timeInMillies;
int seconds = (int) (finalTime / 1000);
int minutes = seconds / 60;
int hours = minutes / 60;
seconds = seconds % 60;
int milliseconds = (int) (finalTime % 1000);
String timer = ("" + String.format("%02d", hours) + " : "
+ String.format("%02d", minutes) + " : "
+ String.format("%02d", seconds));
myHandler.postDelayed(this, 0);
sendLocalBroadcast(timer);
}
};
【问题讨论】:
-
你有预付款吗?
标签: java android string time timer