【发布时间】:2014-10-02 11:07:55
【问题描述】:
您好,我正在尝试将 GMT 时间显示为我的设备时间。 我的设备时区是 EDT。
我得到了一个字符串形式的 GMT 时间
// GMT Time-----2014-11-27 19:32:00
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"HH:mm:ss";
NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
[dateFormatter setTimeZone:gmt];
NSDate *startDate = [dateFormatter dateFromString:@"2014-11-27 19:32:00"];
我将这个开始日期设为 -
//startDate---2014-11-27 19:32:00 +0000
现在我正在尝试将其转换为我的当地时间
NSDateFormatter *dateFormatter2 = [[NSDateFormatter alloc] init];
dateFormatter2.dateFormat = @"hh:mm a";
NSTimeZone *local = [NSTimeZone localTimeZone];
[dateFormatter2 setTimeZone:[NSTimeZone localTimeZone]];
NSString *startDateStr = [dateFormatter2 stringFromDate:startDate];
根据我的时区 (EDT),结果必须是 - 下午 3:32 但是我的时间错了
//startDateStr---02:32 PM
我已经打印了我与 GMT 的时区差异
NSLog(@"TimeZone %d",[[NSTimeZone localTimeZone] secondsFromGMT]);
// TimeZone -14400 - this correct and as per this the startDate must be 03:32 PM
我在哪里犯了错误? 请帮帮我
【问题讨论】:
标签: ios objective-c iphone nsdate nstimezone