NSTimeZone表示时区信息。 有下面几种初始化方法:
1. + (id)timeZoneWithName:(NSString *)aTimeZoneName / - (id)initWithName:(NSString *)aName
根据时区名称初始化。可以调用NSTimeZone的类方法 + (NSArray *)knownTimeZoneNames来返回所有已知的时区名称。
NSTimeZone *zone = [[NSTimeZone alloc] initWithName:@"America/Chicago"];
//NSTimeZone *zone = [NSTimeZone timeZoneWithName:@"America/Chicago"];
NSLog(@"%@",zone);
打印出:America/Chicago (CST) offset -21600
2. + (id)timeZoneWithAbbreviation:(NSString *)abbreviation
根据时区缩写初始化。例如:EST(美国东部标准时间)、HKT(香港标准时间)
NSTimeZone *zone = [NSTimeZone timeZoneWithAbbreviation:@"HKT"];
NSLog(@"%@",zone);
打印出:Asia/Hong_Kong (HKT) offset 28800
3. + (NSTimeZone *)systemTimeZone
返回系统时区
NSTimeZone *zone = [NSTimeZone systemTimeZone];