我想通过使用系统当前在我的Android应用程序中显示特定时间的倒计时。提前致谢。我需要设置一个倒数计时器,该计时器应该告诉我们需要多长时间才能确定时间"这段代码中的12:30。
// start time
String string13 = date + " 06:30:00";
Date time13 = new SimpleDateFormat("MM-dd-yy HH:mm:ss").parse(string13);
Calendar calendar13 = Calendar.getInstance();
calendar13.setTime(time13);
// end time
String string14 = date + " 13:30:00";
Date time14 = new SimpleDateFormat("MM-dd-yy HH:mm:ss").parse(string14);
Calendar calendar14 = Calendar.getInstance();
calendar14.setTime(time14);
// exact time
String string15 = date + " 12:30:00";
Date Z = new SimpleDateFormat("MM-dd-yy HH:mm:ss").parse(string15);
Calendar c15 = Calendar.getInstance();
c15.setTime(Z);
答案 0 :(得分:0)
将以下代码用于您的目标。
startB = (Button) this.findViewById(R.id.button1);
startB.setOnClickListener((OnClickListener) this);
text = (TextView) findViewById(R.id.textView1);
@Override
public void onClick(View v) {
new CountDownTimer(30000, 1000) { // adjust the milli seconds here
public void onTick(long millisUntilFinished) {
text.setText(""+String.format("%d min, %d sec",
TimeUnit.MILLISECONDS.toMinutes( millisUntilFinished),
TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished))));
}
public void onFinish() {
text.setText("done!");
}
}.start();
}
或尝试以下链接
http://steve.odyfamily.com/?p=12