+8  A: 

You have to use %@ as the conversion specifier for an NSString. Change your last line to:

NSLog(@"%@:%@:%@", hoursStr, minsStr, secsStr);

%a means something totally different. From the printf() man page:

aA
The double argument is rounded and converted to hexadecimal notation in the style

[-]0xh.hhhp[+-]d

where the number of digits after the hexadecimal-point character is equal to the precision specification.

Carl Norum
Ah I knew it would be something simple that I missed. Thanks.
Gilbert
+5  A: 

Instead of rolling your own string formatting code, you should be using an NSNumberFormatter for numbers or an NSDateFormatter for dates/times. These data formatters take care of localization of format to the user's locale and handle a variety of formats built-in.

For your use, you need to convert your millisecond time into an NSTimeInterval (typedef'd from a double):

NSTimeInterval time = rawtime/1e3;

Now you can use an NSDateFormatter to present the time:

NSDate *timeDate = [NSDate dateWithTimeIntervalSinceReferenceDate:time];
NSString *formattedTime = [NSDateFormatter localizedStringFromDate:timeDate
                                                         dateStyle:NSDateFormatterNoStyle 
                                                         timeStyle:NSDateFormatterMediumStyle];
NSString *rawTime = [[formattedTime componentsSeparatedByString:@" "] objectAtIndex:0];

on OS X where the last line removes the "AM/PM". This will work for any time less than 12 hrs and will give a formatted string in the localized format for HH:MM:SS. On the iPhone, localizedStringFromDate:dateStyle:timeStyle: isn't available (yet). You can achieve the same effect with setTimeStyle:, setDateStyle: and stringFromDate: on a date formatter instance.

Barry Wark
Is localizedStringFromDate available on iphone? Maybe have to use setLocale instead?
DyingCactus
@DyingCactus You're absolutely correct; `localizedStringFromDate:dateStyle:timeStyle` isn't available on iPhone (yet). You can achieve the same functionality using `setDateStyle:` and `setTimeStyle` followed by `stringFromDate:`
Barry Wark