我有一个有效的计时器,但我没有00:00.000形式的前导零。我怎么能做到这一点?这是我的代码:
mEndTime = System.currentTimeMillis();
mTotalTime = mEndTime - mStartTime;
int seconds = (int) (mTotalTime / 1000);
int minutes = seconds / 60;
seconds = seconds % 60;
int millis = (int) mTotalTime % 1000;
String sectime = Integer.toString(seconds);
String milsectime = Integer.toString(millis);
String time = minutes + ":" + sectime + "." + milsectime;
答案 0 :(得分:0)
String time = String.format("%02d:%02d.%03d", minutes, seconds, millis);