Skip to content

Instantly share code, notes, and snippets.

@kylehowells
Created August 21, 2014 15:25
Show Gist options
  • Save kylehowells/d911bc2bba9000a3f2aa to your computer and use it in GitHub Desktop.
Save kylehowells/d911bc2bba9000a3f2aa to your computer and use it in GitHub Desktop.
NSString for seconds. Turns a number of seconds, (i.e 3705), into a string with the format hh:mm:ss (i.e @"1:1:45").
-(NSString*)stringForTimeInSeconds:(NSInteger)time{
NSInteger seconds = time % 60;
NSInteger minutes = (time - seconds) / 60;
NSInteger hours = floorl(minutes / 60);
if (hours > 0) {
minutes -= (hours * 60);
return [NSString stringWithFormat:@"%ld:%ld:%.2ld", (long)hours, (long)minutes, (long)seconds];
}
return [NSString stringWithFormat:@"%ld:%.2ld", (long)minutes, (long)seconds];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment