xcode 如何获取完整的时区名称 ios
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31338724/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get full time zone name ios
提问by PAn Kaj Khatri
How do we get full time zone name in iOS like Indian Standard Time instead of IST.
我们如何在 iOS 中获取完整的时区名称, 例如印度标准时间而不是 IST。
NSTimezone *timeZone=[NSTimeZone localTimeZone];
i am getting GMT but i want it like full form string
我得到 GMT 但我想要它像完整的字符串
回答by Aladin
You can get the name from the name
property:
您可以从name
属性中获取名称:
NSTimeZone *timeZone = [NSTimeZone localTimeZone];
NSLog(@"Name: %@", timeZone.name);
Result:
结果:
2015-07-10 13:31:46.292 APP[2904:50429] Name : Asia/Calcutta
You can to get the name with the desired style NSTimeZoneNameStyle
using - localizedName:locale:
您可以NSTimeZoneNameStyle
使用所需的样式获取名称- localizedName:locale:
NSTimeZone* timeZone = [NSTimeZone timeZoneWithAbbreviation:@"IST"];
NSString* timeZoneName = [timeZone localizedName:NSTimeZoneNameStyleStandard locale:[NSLocale currentLocale]];
NSLog(@"Name : %@", timeZoneName);
Result:
结果:
2015-07-10 13:36:31.771 APP[2940:51197] Name : India Standard Time
If you call [NSTimeZone abbreviationDictionary]
you'll get a dictionary containing all available abbreviations.
如果你打电话,[NSTimeZone abbreviationDictionary]
你会得到一本包含所有可用缩写的字典。
NSLog(@"%@",[NSTimeZone abbreviationDictionary]);
Result :
结果 :
2015-07-10 11:44:05.954 APP[1472:26120] {
ADT = "America/Halifax";
AKDT = "America/Juneau";
AKST = "America/Juneau";
ART = "America/Argentina/Buenos_Aires";
AST = "America/Halifax";
BDT = "Asia/Dhaka";
BRST = "America/Sao_Paulo";
BRT = "America/Sao_Paulo";
BST = "Europe/London";
CAT = "Africa/Harare";
CDT = "America/Chicago";
CEST = "Europe/Paris";
CET = "Europe/Paris";
CLST = "America/Santiago";
CLT = "America/Santiago";
COT = "America/Bogota";
CST = "America/Chicago";
EAT = "Africa/Addis_Ababa";
EDT = "America/New_York";
EEST = "Europe/Istanbul";
EET = "Europe/Istanbul";
EST = "America/New_York";
GMT = GMT;
GST = "Asia/Dubai";
HKT = "Asia/Hong_Kong";
HST = "Pacific/Honolulu";
ICT = "Asia/Bangkok";
IRST = "Asia/Tehran";
IST = "Asia/Calcutta";
JST = "Asia/Tokyo";
KST = "Asia/Seoul";
MDT = "America/Denver";
MSD = "Europe/Moscow";
MSK = "Europe/Moscow";
MST = "America/Denver";
NZDT = "Pacific/Auckland";
NZST = "Pacific/Auckland";
PDT = "America/Los_Angeles";
PET = "America/Lima";
PHT = "Asia/Manila";
PKT = "Asia/Karachi";
PST = "America/Los_Angeles";
SGT = "Asia/Singapore";
UTC = UTC;
WAT = "Africa/Lagos";
WEST = "Europe/Lisbon";
WET = "Europe/Lisbon";
WIT = "Asia/Jakarta";
}
回答by Shoaib
Try this;
尝试这个;
NSTimeZone* timeZone = [NSTimeZone localTimeZone];
NSString* timeZoneName = [timeZone localizedName:NSTimeZoneNameStyleStandard locale:[NSLocale currentLocale]];
NSLog(@"timeZoneName : %@", timeZoneName);
回答by Ganee....
I think you are looking for this
我想你正在寻找这个
NSDictionary *tempDict = [NSTimeZone abbreviationDictionary];
NSTimeZone* timeZone;
NSString* timeZoneName;
for(NSString *str in tempDict){
timeZone = [NSTimeZone timeZoneWithAbbreviation:str];
timeZoneName = [timeZone localizedName:NSTimeZoneNameStyleStandard locale:[NSLocale currentLocale]];
NSLog(@"%@ --- %@", timeZoneName,timeZone);
}
Output will be like...
输出将像...
Eastern Standard Time --- America/New_York (EDT) offset -14400 (Daylight) Atlantic Standard Time --- America/Halifax (ADT) offset -10800 (Daylight)
东部标准时间 --- America/New_York (EDT) offset -14400 (Daylight) 大西洋标准时间 --- America/Halifax (ADT) offset -10800 (Daylight)