有没有办法安排计时器在特定日期开始?

时间:2018-07-11 13:23:57

标签: java android

我希望使倒计时计时器在将来的某个特定时间开始计时。

这是我现在编写的代码。我需要某种类型的时间监听器,以在到达时间时激活计时器。该应用通常是关于带有开始时间和结束时间的招标的。

     CountDownTimer c = new CountDownTimer(tender.getTime(), 1000) {

        public void onTick(long millisUntilFinished) {



            long days = TimeUnit.MILLISECONDS.toDays(millisUntilFinished);
            millisUntilFinished -= TimeUnit.DAYS.toMillis(days);

            long hours = TimeUnit.MILLISECONDS.toHours(millisUntilFinished);
            millisUntilFinished -= TimeUnit.HOURS.toMillis(hours);

            long minutes = TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished);
            millisUntilFinished -= TimeUnit.MINUTES.toMillis(minutes);

            long seconds = TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished);


            if (days == 0) {
                if (hours == 0) {
                    time.setText(minutes + ":" + seconds);
                } else {
                    time.setText(hours + ":" + minutes + ":" + seconds);
                }
            } else if (hours == 0) {
                time.setText(minutes + ":" + seconds);
            } else {
                time.setText(days + " days , " + hours + ":" + minutes + ":" + seconds);
            }



        }

        public void onFinish() {
            time.setText("over");
        }

    };


    if(tender.calcTimer(tender.getStartTender(),tender.getStartTime())>=0){
        time.setText("didn't start yet");
    }
    else if(tender.getTime()<=0){
        time.setText("over");
    }
    if (time.getText().toString().equals(null)) {

        c.start();

    }

0 个答案:

没有答案