Hey all,
i try to convert a value like "898.171813964844" into 00:17:02 (hh:mm:ss).
How can this be done in objective c?
Thanks for help!
Hey all,
i try to convert a value like "898.171813964844" into 00:17:02 (hh:mm:ss).
How can this be done in objective c?
Thanks for help!
-doubleValue
+dateWithTimeIntervalSinceNow:
-descriptionWithCalendarFormat:timeZone:locale:
Assuming you are just interested in hours, minutes and seconds and that the input value is less or equal 86400 you could do something like this:
NSNumber *theDouble = [NSNumber numberWithDouble:898.171813964844];
int inputSeconds = [theDouble intValue];
int hours = inputSeconds / 3600;
int minutes = ( inputSeconds - hours * 3600 ) / 60;
int seconds = inputSeconds - hours * 3600 - minutes * 60;
NSString *theTime = [NSString stringWithFormat:@"%.2d:%.2d:%.2d", hours, minutes, seconds];
Final solution:
NSNumber *time = [NSNumber numberWithDouble:([online_time doubleValue] - 3600)];
NSTimeInterval interval = [time doubleValue];
NSDate *online = [NSDate date];
online = [NSDate dateWithTimeIntervalSince1970:interval];
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"HH:mm:ss"];
NSLog(@"result: %@", [dateFormatter stringFromDate:online]);