您如何正确设置 android 倒计时,使其始终有 2 位数字

how do you properly setup android countdown such that it will always have 2 digits places

如何正确设置 android 倒计时输出,使其始终有 2 位数字?

例如:02:03 或 02:05 将是正确的输出

当前输出:2:3或2:5

我尝试了两种输出相同内容的实现:

g.drawString("TIME: " +  ((milliSec / (1000*60)) % 60) + " : " + ((milliSec / 1000) % 60 ), 150, 110);


g.drawString("TIME: " + String.format("%d : %d ",
        TimeUnit.MILLISECONDS.toMinutes( milliSec),
        TimeUnit.MILLISECONDS.toSeconds(milliSec) -
                TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(milliSec))),150,110);
g.drawString("SCORE: " + board.getScore(), 150,50);

String.format中,改用String.format("%02d:%02d", ...