简体   繁体   English

textview中的显示计时器包含android中的天,小时,分钟和秒

[英]Display timer in textview contain days, hours, minutes and seconds in android

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 to start the timer:- 启动计时器的代码: -

counter = new MyCount (length, 10);

Everything is working fine. 一切都很好。 It shows the timer in text view like as 00:00:00 and the maximum limit is 59:59:59. 它在文本视图中显示计时器,如00:00:00,最大限制为59:59:59。 It means only 60 hours. 这意味着只有60个小时。 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?? 现在我希望限制应该增加,如果用户选择3天然后计时器应该从71:59:59或类似的东西开始,以便倒数计时器的finish()方法应该在3天后调用。我怎么能去做?? Beside it I want to show number of days also in the below format:- 除此之外,我想以下列格式显示天数: -

Days:Hours:minutes:seconds left . 天:小时:分钟:剩余秒数。

How can I achieve that.Please help me to sort out this problem. 我怎样才能做到这一点。请帮我解决这个问题。

I think, you can check the value, if(millisec > 24* 60*60*60*10... ) if so, divide by 24 to get number of days.. 我想,您可以查看值,如果(毫秒> 24 * 60 * 60 * 60 * 10 ...)如果是,则除以24得到天数。

(diff / (1000 * 60 * 60 * 24)); (diff /(1000 * 60 * 60 * 24)); //for counting days //用于计算天数

or int days = (int) (milliseconds / (1000*60*60*24)); 或int days =(int)(毫秒/(1000 * 60 * 60 * 24));

Other method is, You can map with calender object I think.. I am not sure.. just try it out.. 其他方法是,你可以用日历对象映射我认为..我不确定..只是尝试一下..

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 android eclipse:倒数计时器,以小时,分钟和秒为单位 - android eclipse: Countdown timer in hours, minutes and seconds 在android中使用倒计时器显示天数小时分秒的倒计时问题 - Countdown issue while displaying days hours minutes seconds using count down timer in android 在 Android 中获取以天、小时、分钟和秒为单位的日期和时差 - Get Date and Time Difference in Days, Hours, Minutes and Seconds in Android 创建一个计时器,以秒,分,小时,天为单位显示事件剩余时间 - Creating a Timer which shows time left for an event in seconds , minutes , hours , days 我正在尝试创建一个倒计时计时器,其中包括事件的天数,小时数,分钟数和秒数? - I am trying to create a countdown timer which includes days, hours, minutes and seconds of an event? JodaTime:将周期打印为天:小时:分钟:秒 - JodaTime: Print Period as Days:Hours:Minutes:Seconds 计时器减少文本视图中显示的时间,以分钟和秒为单位 - Timer decrease time displayed in textview with minutes and seconds 如何在Android中的天,小时(24),分钟(60),秒(60)中获得两个日期之间的差异 - How to get difference between two dates in Days, Hours (24), Minutes (60), Seconds(60) in android 显示java中2个日期之间的天,小时,分钟 - Display days, hours, minutes in between 2 dates in java 倒数计时器不更新Android中的分钟和小时 - Count Down Timer Not updating minutes and hours in Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM