【发布时间】:2016-05-27 11:41:12
【问题描述】:
我正在使用此代码获取时区
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);
这段代码的响应就像我想要的那样
"(GMT+01:00)Africa/Libreville",
"(GMT+00:00)Africa/Lome",
"(GMT+01:00)Africa/Luanda",
"(GMT+02:00)Africa/Lubumbashi",
"(GMT+02:00)Africa/Lusaka",
"(GMT+01:00)Africa/Malabo",
"(GMT+02:00)Africa/Maputo",
"(GMT+02:00)Africa/Maseru",
"(GMT+02:00)Africa/Mbabane",
"(GMT+03:00)Africa/Mogadishu",
"(GMT+00:00)Africa/Monrovia",
"(GMT+03:00)Africa/Nairobi",
"(GMT+01:00)Africa/Ndjamena",
"(GMT+01:00)Africa/Niamey",
"(GMT+00:00)Africa/Nouakchott",
"(GMT+00:00)Africa/Ouagadougou",
"(GMT+01:00)Africa/Porto-Novo",
"(GMT+00:00)Africa/Sao_Tome",
"(GMT+02:00)Africa/Tripoli",
"(GMT+01:00)Africa/Tunis",
我必须在我的标签中显示这种类型
但我要做的是,当我们单击仅保存(非洲/的黎波里)时,数据库中的这一部分将被保存,我不知道如何执行此操作。 请帮帮我
【问题讨论】:
-
NSString *strResult = [NSString stringWithFormat:@"(GMT%@)%@",mu,obj];你添加 GMT 字符串
-
没有得到你想要的?你想要这个列表中的特定时区吗?
-
不,我得到的时区是正确的,但我必须只保存非洲/尼亚美,这部分列表不是 (GMT+01:00)..
-
表示你不想
(GMT+01:00)这个括号在列表中? -
我不想保存这个支架部分@Lion
标签: ios objective-c timezone