我正在尝试对android中的事件进行倒计时。事件的日期和时间存储在数据库中,但倒计时返回的天数超出了应有的天数。
这是尝试过的。
String EventDate="2013-12-26 15:00:00";
SimpleDateFormat FormatDate = new SimpleDateFormat("yyyy-MM-dd HH:mm",Locale.US);
FormatDate.setTimeZone(TimeZone.getTimeZone("GMT+1"));
try {
Date date = FormatDate.parse(mm);
} catch (Exception e) {
// TODO: handle exception
}
Long ToCount=date.getTime();
CountDownTimer cdt = new CountDownTimer(ToCount, 1000) {
public void onTick(long millisUntilFinished) {
EventTv.setText(""+ String.format(
"%d Days,%d Hours, %d min, %d sec",
TimeUnit.MILLISECONDS.toDays(millisUntilFinished),
TimeUnit.MILLISECONDS.toHours(millisUntilFinished),
TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished),
TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished))
));
}
public void onFinish() {
// TODO Auto-generated method stub
EventTv.setText("done");
}
}.start();
但如果我运行应用程序,TextView 会显示(16059days,3875429hours,23125799min)
.
请帮助我知道我做错了什么?