1

Possible Duplicate:
How can I pad an integer on the left with zeros?

In my iPhone app I am calculating time in this manner.

int timeTakeInSeconds = (int)(self.timeTaken*[constants timer]);
int timeTakenMins= (int)(timeTakeInSeconds/60);
int timeTakenSecs =(int)(timeTakeInSeconds%60);
NSString *timeText = [NSString stringWithFormat:@"Time %d:%d",timeTakenMins,timeTakenSecs];

By this I am getting second as 1,2,...10, 11..and so on. But I need as 01, 02, 03...10, 11, 12..and so on..How can I do this? Is there any way to do this by number formatter? Please help.

Community
  • 1
  • 1
hgpl
  • 869
  • 4
  • 11
  • 20

1 Answers1

7

Try using %d:%02d instead of just %d:%d. This is using the standard C-style printf formatting options. The documentation can be found at Format Specifiers.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285