Skip to content

Instantly share code, notes, and snippets.

@vitoziv
Last active December 28, 2015 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vitoziv/7481197 to your computer and use it in GitHub Desktop.
Save vitoziv/7481197 to your computer and use it in GitHub Desktop.
convertTimeFromSeconds.m
- (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