Created
April 22, 2012 23:47
-
-
Save rojotek/2467579 to your computer and use it in GitHub Desktop.
ObjectiveC format time snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (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