0

I have a timer that works, but I don't have leading zeros in the form of 00:00.000. How can I make that happen? Here's my code:

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;
Milap
  • 147
  • 1
  • 6
  • 15
  • See also [How to format a duration in java? (e.g format H:MM:SS)](http://stackoverflow.com/questions/266825/how-to-format-a-duration-in-java-e-g-format-hmmss) – shmosel May 10 '16 at 23:56
  • check this http://stackoverflow.com/a/37065062/2032561 – Bharatesh May 11 '16 at 07:11

1 Answers1

0
String time = String.format("%02d:%02d.%03d", minutes, seconds, millis);
shmosel
  • 49,289
  • 6
  • 73
  • 138