Skip to content

Instantly share code, notes, and snippets.

@AlexHedley
Created October 1, 2014 22:05
Show Gist options
  • Save AlexHedley/5bc12ef4902bf1ce8fb7 to your computer and use it in GitHub Desktop.
Save AlexHedley/5bc12ef4902bf1ce8fb7 to your computer and use it in GitHub Desktop.
Formatted Time from Seconds to Hours/Minutes/Seconds
- (NSString *)formattedTime {
int seconds = [self.duration intValue] % 60;
int minutes = [self.duration intValue] / 60;
int hours = [self.duration intValue] / 3600;
return [NSString stringWithFormat:@"%02d:%02d:%02d", hours, minutes, seconds];
}
//Better solution
- (NSString *)timeFormatted:(int)totalSeconds{
int seconds = totalSeconds % 60;
int minutes = (totalSeconds / 60) % 60;
int hours = totalSeconds / 3600;
return [NSString stringWithFormat:@"%02d:%02d:%02d",hours, minutes, seconds];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment