code :
-(NSString *)getSeconds:(NSString *)timeString {
NSArray *time = [timeString componentsSeparatedByString: @":"];
NSString *hours = [time objectAtIndex: 0];
NSString *mins = [time objectAtIndex: 1];
NSString *secs = [time objectAtIndex: 2];
int total = (([hours intValue] * 3600)+ ([mins intValue] * 60) + [secs intValue]);
NSString* totalSeconds = [NSString stringWithFormat:@"%d", total];
return totalSeconds;
}
usage:
NSLog(@"Seconds : %@", [self getSeconds: @"01:30:48"]);
No comments:
Post a Comment