Search code examples
objective-cprogramming-languagessyntaxformatting

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? 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.


Solution

  • unsigned int time = 1100;
    
    NSString *strTime = [NSString stringWithFormat:@"%02u:%02u", time / 100, time % 100];