Created
August 21, 2014 15:25
-
-
Save kylehowells/d911bc2bba9000a3f2aa to your computer and use it in GitHub Desktop.
NSString for seconds. Turns a number of seconds, (i.e 3705), into a string with the format hh:mm:ss (i.e @"1:1:45").
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*)stringForTimeInSeconds:(NSInteger)time{ | |
| NSInteger seconds = time % 60; | |
| NSInteger minutes = (time - seconds) / 60; | |
| NSInteger hours = floorl(minutes / 60); | |
| if (hours > 0) { | |
| minutes -= (hours * 60); | |
| return [NSString stringWithFormat:@"%ld:%ld:%.2ld", (long)hours, (long)minutes, (long)seconds]; | |
| } | |
| return [NSString stringWithFormat:@"%ld:%.2ld", (long)minutes, (long)seconds]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment