Skip to content

Instantly share code, notes, and snippets.

@chlady
Created July 28, 2010 03:13
Show Gist options
  • Select an option

  • Save chlady/493257 to your computer and use it in GitHub Desktop.

Select an option

Save chlady/493257 to your computer and use it in GitHub Desktop.
/// Take an NSTimeInterval and return a string representation in the format h:mm:ss
+ (NSString *)formatWithInterval: (NSTimeInterval)interval
{
NSAssert(interval >= 0, @"interval must be >= 0");
unsigned long seconds = interval;
unsigned long minutes = seconds / 60;
seconds %= 60;
unsigned long hours = minutes / 60;
minutes %= 60;
NSMutableString *result = [NSMutableString string];
if(hours)
[result appendFormat: @"%d:", hours];
[result appendFormat: @"%02d:", minutes];
[result appendFormat: @"%02d", seconds];
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment