2013-11-25 156 views
-3

我区名称“美国/旧金山更改时区从PST到GMT

NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"America/San francisco"]; 

它给出的时区PST。但我需要在GMT时间为(GMT-8)的偏移量-28800

感谢

回答

0

NSTimeZone方法timeZoneForSecondsFromGMT :构造了一个时区与GMT +/-名。这样的时区没有夏时制。构建它是太平洋时间在特定日期正确,您可以使用secondsFromGMTForDate:,以获得正确的偏移时区偏移:

NSTimeZone *pacificTimeZone = [NSTimeZone timeZoneWithName:@"America/Los_Angeles"]; 
NSDate *targetDate = ...; 
NSTimeZone *offsetTimeZone = [NSTimeZone timeZoneForSecondsFromGMT:[pacificTimeZone secondsFromGMTForDate:targetDate]]; 
+0

感谢,很多它为我工作。 :) – user1841079