Quote:
Originally Posted by Eagle11
I have a question about formatting a string. I have a timer in my app that displays hour:min:sec. Right now I am using this line:
Code:
NSString *nssTimer = [NSString stringWithFormat:@"%2i:%2i:%2i", nsiTimerHour, nsiTimerMin, nsiTimerSeconds];
to format the string. The problem is that is ends of looking like this
#: #: #
when the numbers are less than ten. I want it to look like this
##:##:##
regardless of what the values are.
Is there a way to achieve that?
|
I have some code that displays minutes:seconds:tenths. I want the minutes and seconds to be two digits, even if there are less than 10 of either. The formatting that works for me is:
Code:
[self setText:[NSString stringWithFormat:@"%02d:%02d.%1d",dispMins,dispSecs,tsecs]];
Will give output, of:
for 2 minutes, 8 and 3 tenths seconds.
Good luck!