iosobjective-ctimezonegmt

How to get this type of timezone list in uitableview?


I am working on one application and I have to show this type of timezone list in the tableview .

I have tried this :-

 NSMutableArray *timeZoneArray  = [[NSMutableArray alloc] initWithArray:[NSTimeZone knownTimeZoneNames]];
            NSMutableArray *abbreviationArray = [[NSMutableArray alloc] init];

            for (int count = 0; count < [timeZoneArray count] - 1; count = count + 1) {
                NSString *timeZoneStr = [timeZoneArray objectAtIndex:count];
                [abbreviationArray addObject: [timeZoneStr stringByAppendingFormat:@"(%@)",[[NSTimeZone timeZoneWithName: timeZoneStr] abbreviation]]];
            }
            NSLog(@"Abbreviation : %@",abbreviationArray);

and i am getting this type of list

enter image description here

but i want this type of list

enter image description here

please help me


Solution

  • Try this it's returning result like

    "(GMT+00:00)Africa/Abidjan"
    
    NSMutableArray *arrResult = [NSMutableArray new];
    NSDateFormatter *dateFormatter = [NSDateFormatter new];
    NSDate *myDate = [NSDate date];
    [dateFormatter setDateStyle:NSDateFormatterLongStyle];
    [dateFormatter setTimeStyle:NSDateFormatterLongStyle];
    [dateFormatter setDateFormat:@"ZZZ"];
    [[NSTimeZone knownTimeZoneNames] enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:obj];
        [dateFormatter setTimeZone:timeZone];
        NSString *dateString = [dateFormatter stringFromDate: myDate];
        NSMutableString *mu = [NSMutableString stringWithString:dateString];
        [mu insertString:@":" atIndex:3];
        NSString *strResult = [NSString stringWithFormat:@"(GMT%@)%@",mu,obj];
        [arrResult addObject:strResult];
    }];
    NSLog(@"%@", arrResult);