PAn*_*tri 8 xcode timezone objective-c nstimezone ios
我们如何在iOS中获得全时区名称, 如印度标准时间而不是IST.
NSTimezone *timeZone=[NSTimeZone localTimeZone];
Run Code Online (Sandbox Code Playgroud)
我正在获得GMT,但我希望它像完整的形式字符串
Ala*_*din 12
您可以从name酒店获取名称:
NSTimeZone *timeZone = [NSTimeZone localTimeZone];
NSLog(@"Name: %@", timeZone.name);
Run Code Online (Sandbox Code Playgroud)
结果:
2015-07-10 13:31:46.292 APP[2904:50429] Name : Asia/Calcutta
Run Code Online (Sandbox Code Playgroud)
您可以NSTimeZoneNameStyle使用所需的样式获取名称- localizedName:locale:
NSTimeZone* timeZone = [NSTimeZone timeZoneWithAbbreviation:@"IST"];
NSString* timeZoneName = [timeZone localizedName:NSTimeZoneNameStyleStandard locale:[NSLocale currentLocale]];
NSLog(@"Name : %@", timeZoneName);
Run Code Online (Sandbox Code Playgroud)
结果:
2015-07-10 13:36:31.771 APP[2940:51197] Name : India Standard Time
Run Code Online (Sandbox Code Playgroud)
如果你打电话给[NSTimeZone abbreviationDictionary]你,你会得到一本包含所有可用缩写的字典.
NSLog(@"%@",[NSTimeZone abbreviationDictionary]);
Run Code Online (Sandbox Code Playgroud)
结果:
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";
}
Run Code Online (Sandbox Code Playgroud)
试试这个;
NSTimeZone* timeZone = [NSTimeZone localTimeZone];
NSString* timeZoneName = [timeZone localizedName:NSTimeZoneNameStyleStandard locale:[NSLocale currentLocale]];
NSLog(@"timeZoneName : %@", timeZoneName);
Run Code Online (Sandbox Code Playgroud)