Skip to content

Instantly share code, notes, and snippets.

@bluebanboom
Created June 12, 2012 14:54
Show Gist options
  • Save bluebanboom/2918003 to your computer and use it in GitHub Desktop.
Save bluebanboom/2918003 to your computer and use it in GitHub Desktop.
Create NSString from NSTimeInterval with format HH:MM::SS
- (NSString *)stringFromTimeInterval:(NSTimeInterval)interval
{
NSInteger ti = (NSInteger)interval;
NSInteger seconds = ti % 60;
NSInteger minutes = (ti / 60) % 60;
NSInteger hours = (ti / 3600);
NSString *time = nil;
if (hours > 0) {
time = [NSString stringWithFormat:@"%02i:%02i:%02i", hours, minutes, seconds];
}
else {
time = [NSString stringWithFormat:@"%02i:%02i", minutes, seconds];
}
return time;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment