开发者

Fastest way to format a String using concatenation and manipulation

String temp = "";

temp = String.format("%02d", ""+hour)+":"+String.format("%02d", ""+min)+":"+String.format("%02d", ""+sec);

Is this the fastest way to format the numbers with concatenation to specify leading zeroes, or is there another way?

I have to display the String in the format 00:00:00. The hour, min, and sec are int va开发者_如何学Pythonriables which start from 0 and are put into the Thread which counts the time elapsed and displays this time accordingly. Is this the correct way, or is there any better way?


Try this. I assume that hour, min and sec are ints.

String temp = "";
temp = String.format("%02d:%02d:%02d", hour, min, sec);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜