-2

I am trying to format a string a certain way. Currently I have

String timeString = hour + ":" + min + ":" + sec ;

however I have hour min and sec as integers and whenever they are a single digit i would like to add a placeholder 0 in front. How would I do that?

Edit: This did not answer my question.

Community
  • 1
  • 1
wawiiii
  • 15
  • 5

1 Answers1

3

You could use String.format(String, Object...) to format your numbers like

String timeString = String.format("%02d:%02d:%02d", hour, min, sec);
Elliott Frisch
  • 183,598
  • 16
  • 131
  • 226