ios - 如何在uitableview中获取这种类型的时区列表?

标签 ios objective-c timezone gmt

我正在处理一个应用程序,我必须在 tableview 中显示这种类型的 timezone 列表。

我已经试过了:-

 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);

我得到了这种类型的列表

enter image description here

但我想要这种类型的列表

enter image description here

请帮帮我

最佳答案

试试这个,返回结果如下

"(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);

关于ios - 如何在uitableview中获取这种类型的时区列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37452180/

相关文章:

ios - 如何使用 prepareForSegue 方法从 View Controller 推送到导航 View Controller ?

iphone - xmppframework (iOS) 和配置身份验证类型

javascript - uiwebview html表单上的图像压缩

objective-c - Google map 路由语法

php - Mysql默认时区

ios - iOS 7 中的 NSDateFormatter 字符串

ios - 使用 FBSessionLoginBehaviorForcingWebView 登录 Facebook

ios - 基于字典键的数组排序 :value in swift

ios - 如何获取完整的时区名称 ios

python - 如何在 Django 中设置我自己的时区?