在TextView中显示定时器包含天,小时,分钟和秒的android
我使用的倒数计时器,以显示文本view.It工作正常左边的时间。
下面是code: - \\
I am using countdown timer to show the left time in text view.It is working fine. Below is the code:-\
public class MyCount extends CountDownTimer {
Context mContext;
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
public void onTick (long millisUntilFinished) {
MainActivity.timeDisplay.setText(formatTime(millisUntilFinished));
}
public void onFinish() {
AutomaticCallRecorderStaticMethod.startRecording();
}
}
public String formatTime(long millis) {
output = "";
long seconds = millis / 1000;
long minutes = seconds / 60;
long hours=minutes/ 60;
seconds = seconds % 60;
minutes = minutes % 60;
hours=hours%60;
String secondsD = String.valueOf(seconds);
String minutesD = String.valueOf(minutes);
String hoursD=String.valueOf(hours);
if (seconds < 10)
secondsD = "0" + seconds;
if (minutes < 10)
minutesD = "0" + minutes;
if (hours < 10)
hoursD = "0" + hours;
output = hoursD+" : "+minutesD + " : " + secondsD;
return output;
}
code启动定时器: -
Code to start the timer:-
counter = new MyCount (length, 10);
一切工作正常。这表明像为00:00:00在文本视图定时器
和最大极限为59:59:59。这意味着只有60个小时。现在我想的限制应该增加,如果用户选择3天,然后定时器应71:59:59或者类似的东西开始,这样倒计时的结束()方法应该经过3 days.How叫我能去做??
除了它,我想也显示在下面的格式天数: -
Everything is working fine. It shows the timer in text view like as 00:00:00 and the maximum limit is 59:59:59. It means only 60 hours. Now I want that the limit should be increased if the user select 3 days then the timer should start from 71:59:59 or something like that so that the finish() method of countdown timer should be called after 3 days.How can I do that?? Beside it I want to show number of days also in the below format:-
天:小时:分钟:秒左
如何才能实现that.Please帮我理清这个问题。
How can I achieve that.Please help me to sort out this problem.
我想,你可以检查的价值,
如果(毫秒> 24 * 60 * 60 * 60 * 10 ...)
如果是的话,24分获得天数。
I think, you can check the value, if(millisec > 24* 60*60*60*10... ) if so, divide by 24 to get number of days..
(差异/(1000 * 60 * 60 * 24)); //计数天
(diff / (1000 * 60 * 60 * 24)); //for counting days
或
INT天数=(INT)(毫秒/(1000 * 60 * 60 * 24));
or int days = (int) (milliseconds / (1000*60*60*24));
另一种方法是,
你可以用日历对象映射我想..我不知道..只是尝试一下。
Other method is, You can map with calender object I think.. I am not sure.. just try it out..