2
正如您可以看到最後一次呼叫onTick正在發生2秒鐘,然後接下來的呼叫將近2秒鐘後。倒計時器跳過一些毫秒
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tv = new TextView(this);
this.setContentView(tv);
SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy, HH:mm:ss:SSS");
formatter.setLenient(false);
newTime = "31.12.2015, 23:59:59:999";
try {
newDate = formatter.parse(newTime);
milliseconds = newDate.getTime();
currentTime = System.nanoTime();
diff = milliseconds - currentTime;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
MyCount counter = new MyCount(milliseconds, 1000);
counter.start();
}
CountDownTimer
public class MyCount extends CountDownTimer {
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {
}
@Override
public void onTick(long millisUntilFinished) {
serverUptimeSeconds = (millisUntilFinished - System
.currentTimeMillis())/1000;
String serverUptimeText = String.format(
"%d days %d hours %d minutes %d seconds",
serverUptimeSeconds/86400,
(serverUptimeSeconds % 86400)/3600,
((serverUptimeSeconds % 86400) % 3600)/60,
((serverUptimeSeconds % 86400) % 3600) % 60);
tv.setText(serverUptimeText);
}
}
輸出:
10 seconds
8 seconds
6 seconds
4 seconds
P.S〜檢查視頻更多信息
https://www.dropbox.com/s/7b3hme5ekdqpfi1/79789789.avi?dl=0
你能在我的代碼修改..烏爾只是顯示小時,分鐘,秒 – Gattsu
只是做了它,希望它有助於現在;) – iGoDa
我需要幾天也..在這部分plz幫助 – Gattsu