How to format longs in android to always display two digits

后端 未结 5 1060
无人共我
无人共我 2021-02-12 23:19

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

5条回答
  •  逝去的感伤
    2021-02-12 23:45

    TextView time; 
    int hour=0,minute=0,second=0;
    time.setText((String.format("%02d", hour))+":"+(String.format("%02d", minute))+":"+(String.format("%02d", second)));
    

    time to TextView

提交回复
热议问题