我试图得到所有现有时区的缩写。[NSTimeZone abbreviationDictionary]只返回其中的一部分,但是像AEST (来自澳大利亚/布里斯班)这样的部分不出现。
我发现用这个代码
NSDate *myDate = [NSDate date];
NSDateFormatter *f = [[NSDateFormatter alloc] init];
[f setDateStyle:NSDateFormatterLongStyle];
[f setTimeStyle:NSDateFormatterLongStyle];
[f setDateFormat:@"zzzz"];
NSArray *timeZoneNames = [NSTimeZone knownTimeZoneNames];
for (NSString *name1 in timeZoneNames)
{
NSTimeZone *tz = [NSTimeZone timeZoneWithName:name1];
[f setTimeZone:tz];
DLog(@"%@ = \"%@\" = %@", [tz abbreviation], name1, [f stringFromDate:myDate]);
}我可以得到所有可用的时区缩写和全名,如:
EET = "Europe/Kiev" = Eastern European Standard Time
WET = "Europe/Lisbon" = Western European Standard Time
CET = "Europe/Ljubljana" = Central European Standard Time
GMT = "Europe/London" = Greenwich Mean Time但是时区名称与地区有关(我当前的[NSLocale currentLocalelocaleIdentifier]是en_GB),所以我得到了如下结果:
GMT-4 = "America/New_York" = Eastern Daylight Time
GMT-4 = "America/Nipigon" = Eastern Daylight Time
GMT-8 = "America/Nome" = Alaska Daylight Time
GMT-2 = "America/Noronha" = Fernando de Noronha Standard Time有什么方法我可以得到所有现有的时区缩写,而不是GMT-X?
任何帮助都是非常感谢的:)
谢谢!
发布于 2014-03-13 18:22:48
你没有得到这些缩写,因为它们不标准。和大多数电脑制造商一样,苹果也使用半官方的IANA时区数据库。IANA并不认为"AEST“是一个标准缩写(事实上,他们的australasia文件包含了关于这个问题的重要讨论),所以它没有包含在iOS的时区数据中。
发布于 2014-03-11 12:48:13
使用名称获取所有区域并获取secondsFromGMT:
#import <Foundation/Foundation.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
for(NSString *name in [NSTimeZone knownTimeZoneNames]) {
NSTimeZone *z = [NSTimeZone timeZoneWithName:name];
NSLog(@"%@", z.name); //name
NSLog(@"GMT-%d", (z.secondsFromGMT/60)/60); //GMT-%D%
NSLog(@"%@", z.abbreviation); //abbreviation
}
}
}https://stackoverflow.com/questions/22326015
复制相似问题