如何根据currentLocale获取knownTimeZoneNames

时间:2014-04-23 22:37:20

标签: ios objective-c nstimezone nslocale

我想创建一个以用户语言自动翻译的knownTimeZoneNames列表 对于效果很好的国家/地区,我有此代码,但我无法为knowntimeZoneNames成功完成此操作。

NSLocale *localeTwo = [NSLocale currentLocale];
NSArray *countryArray = [NSLocale ISOCountryCodes];
NSMutableArray *sortedCountryArray = [[NSMutableArray alloc] init];

for (NSString *countryCode in countryArray) {        
    NSString *displayNameString = [localeTwo displayNameForKey:NSLocaleCountryCode value:countryCode];
    [sortedCountryArray addObject:displayNameString];      
    NSLog(@"NSDisplayNameString : %@", displayNameString);
}        
[sortedCountryArray sortUsingSelector:@selector(localizedCompare:)];   
[sortedCountryArray sortUsingSelector:@selector(localizedCompare:)];

1 个答案:

答案 0 :(得分:0)

[NSTimeZone knownTimeZoneNames]制造了这个东西。尝试:

NSArray * knownTimeZoneArray = [NSTimeZone knownTimeZoneNames];    
NSLog(@"knownTimeZoneArray = %@", knownTimeZoneArray);