我正在对每周的星期六进行倒计时,我希望当计数器达到零(星期六)时,它将在下一个星期六再次激活。但我不知道如何每周更新日期。
我正在使用的代码如下:
private void CountDown() {
SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy, HH:mm:ss");
formatter.setLenient(false);
String endTime = "12.03.2018, 15:05:36";
Date endDate;
try {
endDate = formatter.parse(endTime);
milliseconds = endDate.getTime();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
startTime = System.currentTimeMillis();
diff = milliseconds - startTime;
mCountDownTimer = new CountDownTimer(milliseconds, 1000) {
@Override
public void onTick(long millisUntilFinished) {
startTime=startTime-1;
Long serverUptimeSeconds =
(millisUntilFinished - startTime) / 1000;
String daysLeft = String.format("%d", serverUptimeSeconds / 86400);
txtdays.setText(daysLeft);
String hoursLeft = String.format("%d", (serverUptimeSeconds % 86400) / 3600);
txthour.setText(hoursLeft);
String minutesLeft = String.format("%d", ((serverUptimeSeconds % 86400) % 3600) / 60);
txtmins.setText(minutesLeft);
String secondsLeft = String.format("%d", ((serverUptimeSeconds % 86400) % 3600) % 60);
txtsec.setText(secondsLeft);
}
@Override
public void onFinish() {
}
}.start();
}
谢谢您的帮助。