I need to convert time collected in milliseconds (e.g. 116124) to typical format of time like this: 03:12:32:04.
I don't know how to simple do it... Could you help me?
According to an Apple Dev forum linked here:
https://discussions.apple.com/thread/2350190?start=0&tstart=0
you have to do it yourself. Here is the function you can use that will return a formated string:
- (NSString *) formatInterval: (NSTimeInterval) interval{
unsigned long milliseconds = interval;
unsigned long seconds = milliseconds / 1000;
milliseconds %= 1000;
unsigned long minutes = seconds / 60;
seconds %= 60;
unsigned long hours = minutes / 60;
minutes %= 60;
NSMutableString * result = [NSMutableString new];
if(hours)
[result appendFormat: @"%d:", hours];
[result appendFormat: @"%2d:", minutes];
[result appendFormat: @"%2d:", seconds];
[result appendFormat: @"%2d",milliseconds];
return result;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With