没有GMT偏移的IOS时区缩写。需要直接像IST,EST等

时间:2017-07-26 13:04:53

标签: ios objective-c nstimezone

 NSTimeZone *timezone = [NSTimeZone systemTimeZone];
 NSString *timeZoneAbberivation = [timezone abbreviation];

timeZoneAbberivation像GMT + 5:30那样打印。但我需要GMT + 5:30作为IST打印。 (IST是印度/ Kolkatta)。

假设它是美国/纽约时区,我需要它作为EST等。

2 个答案:

答案 0 :(得分:3)

您可以使用NSDateFormatter。查看提供“短特定非位置格式”的z格式参数

NSDateFormatter Date Formatting Table

答案 1 :(得分:0)

在Swift中你可以使用它:

let  zone = TimeZone.current.identifier
print(zone)

在Objective-C中你可以使用:

NSTimeZone* timeZone = [NSTimeZone timeZoneWithAbbreviation:@"IST"];

NSString* timeZoneName = [timeZone localizedName:NSTimeZoneNameStyleStandard 
                                          locale:[NSLocale currentLocale]];
NSLog(@"Name : %@", timeZoneName);
相关问题