Created
June 12, 2012 14:54
-
-
Save bluebanboom/2918003 to your computer and use it in GitHub Desktop.
Create NSString from NSTimeInterval with format HH:MM::SS
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 *)stringFromTimeInterval:(NSTimeInterval)interval | |
{ | |
NSInteger ti = (NSInteger)interval; | |
NSInteger seconds = ti % 60; | |
NSInteger minutes = (ti / 60) % 60; | |
NSInteger hours = (ti / 3600); | |
NSString *time = nil; | |
if (hours > 0) { | |
time = [NSString stringWithFormat:@"%02i:%02i:%02i", hours, minutes, seconds]; | |
} | |
else { | |
time = [NSString stringWithFormat:@"%02i:%02i", minutes, seconds]; | |
} | |
return time; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment