Use NSTimeInterval (this is basically a double containing the number of seconds). To save it to CoreData :
[NSNumber numberWithDouble:myTimeInterval]
Regarding formatting: if you want to display more than 24 hours, use this:
NSUInteger seconds = (NSUInteger)round(myTimeInterval); NSString *formattedDate = [NSString stringWithFormat:@"%02u:%02u:%02u", seconds / 3600, (seconds / 60) % 60, seconds % 60]; NSLog(@"%@", formattedDate);
If you don't want more than 24 hours to go, you can use NSDate and NSDateFormatter :
NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:myTimeInterval]; NSDateFormatter *dateFormatter = [NSDateFormatter new]; [dateFormatter setDateFormat:@"HH:mm:ss"]; [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]]; NSString *formattedDate = [dateFormatter stringFromDate:date]; NSLog(@"%@", formattedDate);
source share