Skip to content

Instantly share code, notes, and snippets.

@rojotek
Created April 22, 2012 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rojotek/2467579 to your computer and use it in GitHub Desktop.
Save rojotek/2467579 to your computer and use it in GitHub Desktop.
ObjectiveC format time snippet
+ (NSString *)formatTime: (NSTimeInterval)totalSeconds {
int totalMinutes = (int) (totalSeconds / 60);
int hours = totalMinutes / 60;
int minutes = totalMinutes % 60;
int seconds = (int) (totalSeconds) % 60;
if (hours > 0) {
return [NSString stringWithFormat:@"%02i:%02i:%02i", hours, minutes, seconds];
} else {
return [NSString stringWithFormat:@"%02i:%02i", minutes, seconds];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment