我正在处理一个应用程序,我必须在 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);
我得到了这种类型的列表
但我想要这种类型的列表
请帮帮我
最佳答案
试试这个,返回结果如下
"(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/