0

On Android, how can I include a countdown timer to a date set by me (e.g. 25th December 2013)?

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    Have you tried anything yourself before asking? It's always good to try something so we know how you think and what you know/don't know, and more importantly, so you get a good learning experience out of it. – nanofarad Oct 27 '13 at 12:40
  • 2
    `been developing for Android for a year and a half` -- that's quite a bit of time. What did you try? – devnull Oct 27 '13 at 12:41

2 Answers2

2
  1. You can use Date class of java to format your date set by you, and then you can convert it into millisecond using the Date class.
  2. Now, set your current date which can be collect from system via the Calendar class of java in millisecond.
  3. The difference between these two millisecond data can be converted to any recognizable date format via the Date class once again.

You can use this process.

Hope the answer may help you.

Note: If you still can't find out the code, comment me, I will try to show some code then.

0

Check out CountDownTimer from the Developer's website.

new CountDownTimer(30000, 1000) {

     public void onTick(long millisUntilFinished) {
         mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
     }

     public void onFinish() {
         mTextField.setText("done!");
     }
  }.start();

Get the time difference b/w current date and 25th December 2013 , convert it to millisecons and pass them to CountDownTimer.

Also checkout this answer 1 and answer 2.

Community
  • 1
  • 1
Jitender Dev
  • 6,907
  • 2
  • 24
  • 35