I have a countdown timer which shows seconds from 60 to 0 (1 min countdown timer). When it reaches 1 digit numbers such as 9,8,7.. it shows 9 instead of 09. I tried using
You can accomplish it with DecimalFormat:
NumberFormat f = new DecimalFormat("00"); long time = 9; textView.setText(f.format(time));
Output:
09
Or you can use String.format() as well:
String format = "%1$02d"; // two digits textView.setText(String.format(format, time));