Tuesday, June 19, 2012

Get Seconds from TimeFormat

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:

Swift Operators - Basic Part 3 (Range operators in swift)

Range Operators: Closed Range operators  Half-Open Range Operators One-Sided Ranges Closed Range Operators:  a...b It defines...