【问题标题】:Change Timezone from PST to GMT将时区从 PST 更改为 GMT
【发布时间】:2013-11-25 16:41:14
【问题描述】:

我有时区名称“美国/旧金山”

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

它给出了太平洋标准时间的时区。但我需要 GMT 中的 timeZone 作为 (GMT-8) 偏移量 -28800

谢谢

【问题讨论】:

    标签: objective-c cocoa-touch cocoa


    【解决方案1】:

    NSTimeZone 方法 timeZoneForSecondsFromGMT : 构造一个带有 GMT+/- 名称的时区。这样的时区没有任何夏令时。要为太平洋时间的特定日期构建一个正确的偏移时区,您可以使用secondsFromGMTForDate: 来获得正确的偏移:

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

    【讨论】:

      猜你喜欢
      • 2014-04-22
      • 1970-01-01
      • 1970-01-01
      • 2017-02-05
      • 2012-11-03
      • 2020-01-15
      • 1970-01-01
      • 2011-10-26
      • 1970-01-01
      相关资源
      最近更新 更多