我正在使用以下代码格式化日期字符串:
这是日期字符串的格式:2013-10-08T20:30:00+03:00
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[dateFormatter setDateFormat:@"EEEE"];
NSDateFormatter *formmatter = [[NSDateFormatter alloc] init];
formmatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:SSSZZZ";
NSString *dataString = [meetingData objectForKey:@"start"];
if (![dataString isKindOfClass:[NSNull class]]) {
NSMutableString *mutableDate = [dataString mutableCopy];
[mutableDate deleteCharactersInRange:NSMakeRange(mutableDate.length - 3, 1)];
NSDate *gmtDate = [formmatter dateFromString:mutableDate];
NSDateFormatter *HHMM_Fromatter = [[NSDateFormatter alloc] init];
[HHMM_Fromatter setDateFormat:@"HH:mm"];
self.meetingTime = checkTheObject([HHMM_Fromatter stringFromDate:gmtDate]);
self.meetingDay = checkTheObject([dateFormatter stringFromDate:gmtDate]);
}
输出是self.meetingTime
:19:30self.meetingDay
很好,为什么我失去了 1 小时?