Last active
December 28, 2015 09:48
-
-
Save vitoziv/7481197 to your computer and use it in GitHub Desktop.
convertTimeFromSeconds.m
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 *)convertTimeFromSeconds:(NSString *)seconds | |
{ | |
// Return variable. | |
NSString *result = @""; | |
// Int variables for calculation. | |
int secs = [seconds intValue]; | |
// Convert the seconds to hours, minutes and seconds. | |
int tempHour = secs / 3600; | |
int tempMinute = secs / 60 - tempHour * 60; | |
int tempSecond = secs - (tempHour * 3600 + tempMinute * 60); | |
NSString *hour = [NSString stringWithFormat:@"%.2d", tempHour]; | |
NSString *minute = [NSString stringWithFormat:@"%.2d", tempMinute]; | |
NSString *second = [NSString stringWithFormat:@"%.2d", tempSecond]; | |
if (tempHour == 0) { | |
result = [NSString stringWithFormat:@"%@:%@", minute, second]; | |
} else { | |
result = [NSString stringWithFormat:@"%@:%@:%@",hour, minute, second]; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment