现在我的计时器显示秒数,我可以添加什么来显示0:00格式的时间?
new CountDownTimer((300 * 1000), 1000) {
public void onTick(long millisUntilFinished) {
mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
}
public void onFinish() {
mTextField.setText("Session Completed!");
}
}.start();
答案 0 :(得分:1)
@Override
public void onTick(long millisUntilFinished) {
long temp_long = millisUntilFinished / 1000;
second = temp_long % 60;
hour = temp_long / 3600;
minute = (temp_long / 60) % 60;
String tempTimer;
tempTimer = ((hour < 10) ? "0" + hour : "" + hour)+ ((minute < 10) ? ":0" + minute : ":"+ minute)+ ((second < 10) ? ":0" + second : ":" + second);
mTextField.setText(tempTimer);
}
答案 1 :(得分:1)
试试这个:
Date date = new Date((300 * 1000)* 1000);
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
String dateFormatted = formatter.format(date);
您也可以使用
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss:SSS");
答案 2 :(得分:0)
您可以使用android Chronometer显示倒计时。
http://developer.android.com/reference/android/widget/Chronometer.html