开发者

Is there any short hand on formatting the String?

I am using objective c, and I got some variables like this:

1100
920
845
1439

But I want to change it to :

11:00 
09:20
08:45
14:39

The problem is how can I fill the zero when I got three number only开发者_JS百科? I know the logic can be simple to do it I detect the string length, but is there any way to do it more effectually? Thank you.


unsigned int time = 1100;

NSString *strTime = [NSString stringWithFormat:@"%02u:%02u", time / 100, time % 100];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜