androidtimercountdowntimer

Timer display to countdown


right now I have my timer displaying seconds, what can I add to it to display the time in a 0:00 format?

new CountDownTimer((300 * 1000), 1000) {

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

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

Solution

  • Try this:

    Date date = new Date((300 * 1000)* 1000);
    SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
    String dateFormatted = formatter.format(date);
    

    You can also use

    SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss:SSS");