Link to home
Start Free TrialLog in
Avatar of TheMaximumWeasel
TheMaximumWeasel

asked on

NSTimeInterval to minutes and seconds

I have an integer in seconds, that when converted to minutes is less than 60 minutes (So no need to worry about hours). I want to convert the seconds string to a format like this:
int seconds = 352;

...

NSString *time = @"05:52";

NOTE: minutes must have the 0 in front of it if its less than 10 minutes. Same for seconds obviously :)

Max
ASKER CERTIFIED SOLUTION
Avatar of F. Dominicus
F. Dominicus
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TheMaximumWeasel
TheMaximumWeasel

ASKER

Is it possible you could make that into a c function that uses no objects except for the NSString that is returned? I know the amount of seconds will not be over a day.
I can not see why that could be a requirement. You have to create the NSString somehow. So why not using is as I did? However you can use any C function like e.g

char formatted_string_buf[20];

sprintf("formatted_string_buf, "%0.2d:%02d", minutesAndSeconds.quot, minutesAndSeconds.rem);
then you create the NSString from the C buffer.

Regards
Friedrich
Ok, let me clarify it. You question was fully and AFAIKT correctly answered, now you can accept the solution or not. If you like to get another answer then state precicly what can and what can not be used, but in another question.

Friedrich
Sorry about the slow response I hadn't got around to checking the question.