【问题标题】:iOS 7 date time zone issueiOS 7 日期时区问题
【发布时间】:2013-10-10 07:22:40
【问题描述】:

我正在将 NSDate 对象转换为字符串格式。使用GHKit。内部使用NSDateFormatterstringFromDate

[NSDate date] gh_format:@"yyyy-MM-dd HH:mm:ss zzz" useWeekday:NO]


- (NSString *)gh_format:(NSString *)format useWeekday:(BOOL)useWeekday {
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:format]; 
    NSString *formatted = [dateFormatter stringFromDate:self];
    if (useWeekday) {
        NSString *specialWeekday = [self gh_weekday:dateFormatter]; 
     formatted = [NSString stringWithFormat:@"%@, %@", specialWeekday, formatted];
    }
    [dateFormatter release];
    return formatted;
}

此方法适用于 iOS 5、6,产生以下输出

2013-10-10 10:43:44 GMT+05:00

但是 iOS 7 会产生这样的东西,我的网络服务器无法解析

2013-10-10 10:43:44 GMT+5

【问题讨论】:

    标签: ios timezone ios7


    【解决方案1】:

    尝试使用yyyy-MM-dd HH:mm:ss ZZZZ 作为您的日期格式。

    更多信息请见http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-21
      • 2016-12-14
      • 2015-05-24
      • 1970-01-01
      • 1970-01-01
      • 2017-07-08
      • 2014-10-28
      • 1970-01-01
      相关资源
      最近更新 更多