【发布时间】:2013-11-25 16:41:14
【问题描述】:
我有时区名称“美国/旧金山”
NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"America/San francisco"];
它给出了太平洋标准时间的时区。但我需要 GMT 中的 timeZone 作为 (GMT-8) 偏移量 -28800
谢谢
【问题讨论】:
标签: objective-c cocoa-touch cocoa
我有时区名称“美国/旧金山”
NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"America/San francisco"];
它给出了太平洋标准时间的时区。但我需要 GMT 中的 timeZone 作为 (GMT-8) 偏移量 -28800
谢谢
【问题讨论】:
标签: objective-c cocoa-touch cocoa
NSTimeZone 方法 timeZoneForSecondsFromGMT : 构造一个带有 GMT+/- 名称的时区。这样的时区没有任何夏令时。要为太平洋时间的特定日期构建一个正确的偏移时区,您可以使用secondsFromGMTForDate: 来获得正确的偏移:
NSTimeZone *pacificTimeZone = [NSTimeZone timeZoneWithName:@"America/Los_Angeles"];
NSDate *targetDate = ...;
NSTimeZone *offsetTimeZone = [NSTimeZone timeZoneForSecondsFromGMT:[pacificTimeZone secondsFromGMTForDate:targetDate]];
【讨论】: