Could someone show me an example of the CountDownTimer class for an hour/minute/seconds format, thanks.
I've tried this but it doesn't work
contador.setText(""+String.format(FORMAT,
TimeUnit.MILLISECONDS.toHours(millisUntilFinished),
TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished) - TimeUnit.HOURS.toMinutes(
TimeUnit.MILLISECONDS.toHours(millisUntilFinished)),
TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) - TimeUnit.MINUTES.toSeconds(
TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished))));
The problem is that MILLISECONDS marks it red. It only gives me the MILLISECOND option but, after this, toHours does not appear.
I work with version 5.1 of android.
The class you are looking for is
java.util.concurrent.TimeUnit
. You are probably using the classTimeUnit
from the packageandroid.icu.util
that does not containMILLISECONDS
.Change:
By:
You have several little problems, the first one is undoubtedly to define the correct import that should be:
This to use the class and its constant:
The second is that the hours are incorrectly calculated, the necessary argument is missing. The format I add should be the correct one for the format you want:
Another method that is easier to obtain the desired format would be this:
For both options, as an example a time defined as
05:25:25 PM
would be obtained: