【问题标题】:ISO 8601 Date Formatter in Objective for iPhone not setting offset correctlyiPhone 目标中的 ISO 8601 日期格式化程序未正确设置偏移量
【发布时间】:2012-03-07 15:41:18
【问题描述】:

提前感谢您的帮助。

我正在尝试为我的 iPhone 应用程序创建 ISO 8601 日期格式化程序,但我无法正确输出偏移量。我需要结果时区为格林威治标准时间,我位于美国东部标准时间,当我在 2012 年 3 月 6 日下午 2:33 测试它时,我得到了 2012-03-06T14:33:35+0000

由于区域差异,我需要显示 -05:00 而不是 +0000

我使用的代码是:

            NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
            [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss ZZ"];
            NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
            [dateFormatter setTimeZone:gmt];

            NNSDate *gmtDate  = [[NSDate alloc] init];
            dateString = [dateFormatter stringFromDate:gmtDate];

            NSLog(@"Date String: %@", dateString);

【问题讨论】:

    标签: iphone objective-c ipad nsdateformatter iso8601


    【解决方案1】:

    您是否尝试将时区设置为 EST?这可能会给你你的-0500

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-15
      • 2013-06-29
      相关资源
      最近更新 更多