当我实例化一个简单的NSCalendar并尝试设置时区时,似乎没有任何效果。我是不是漏掉了什么?
NSCalendar *cal = [[NSCalendar alloc] init];
NSTimeZone *tz = [NSTimeZone timeZoneWithName:@"America/Denver"];
NSLog(@"tz:%@", tz);
//outputs: tz:America/Denver (MST) offset -25200
[cal setTimeZone: tz];
NSLog(@"[cal timeZone]:%@", [cal timeZone]);
//outputs: [cal timeZone]:(null)
cal.timeZone = tz;
NSLog(@"cal.timeZone:%@", cal.timeZone);
//outputs: cal.timeZone:(null)发布于 2014-11-07 18:20:17
我想通了。我猜你不能在用[[NSCalendar alloc] init]创建的NSCalendar对象上设置时区。应该是[NSCalendar currentCalendar]。setter必须做一些奇特的事情,而不仅仅是写入值,如果它不是预配置的日历之一,这将不起作用。
https://stackoverflow.com/questions/26798712
复制相似问题