Parse time from seconds to hours:minutes:seconds
[gist https://gist.github.com/5bc12ef4902bf1ce8fb7 /]
This file contains hidden or 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]; | |
} |
- (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];
}