I was working on a HackerRank question where I turn time in 12 hour format (hour:min:sec am/pm) into 24 hour format (hour:min:sec) (eg hh:mm:ss) . I got everything done, with 3 int variables for hour, min, sec respectively and I want to turn them into a string to return. I use a string format like this
String str = String.format("%2d:%2d:%2d", hour, min, sec); but obviously does not work. I read the documentation on string formatter too but I try to get it work like what I was doing. Any suggestions?