Created
October 1, 2014 22:05
-
-
Save AlexHedley/5bc12ef4902bf1ce8fb7 to your computer and use it in GitHub Desktop.
Formatted Time from Seconds to Hours/Minutes/Seconds
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 *)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