NSString 到 NSDate 给出了完全错误的数据(尝试包括时区)
NSString to NSDate gives completely wrong data (tried including timezone)
尝试将日期为 'Saturday 22 August 2015 17:30' 的 NSString 转换为 NSDate,但结果为“2014-12-27 17:30:00 UTC”。我什至不在乎格式是否错误,我只是希望它能正确地将其转换为 NSDate。
currentFixtures.timeDate 是一个包含 'Saturday 22 August 2015 17:30' 的 NSString
fixtureDate 是一个返回 '2014-12-27 17:30:00 UTC'
的 NSDate
NSDateFormatter *dateFormatFixture = [[NSDateFormatter alloc]init];
[dateFormatFixture setDateFormat:@"EEEE d MMMM YYYY HH:mm"];
[dateFormatFixture setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en-GB"]];
[dateFormatFixture setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
NSDate *fixtureDate = [[NSDate alloc] init];
fixtureDate = [dateFormatFixture dateFromString:currentFixture.timeDate];
EEEE d MMMM yyyy H:m 有效,感谢 maddy
尝试将日期为 'Saturday 22 August 2015 17:30' 的 NSString 转换为 NSDate,但结果为“2014-12-27 17:30:00 UTC”。我什至不在乎格式是否错误,我只是希望它能正确地将其转换为 NSDate。
currentFixtures.timeDate 是一个包含 'Saturday 22 August 2015 17:30' 的 NSString fixtureDate 是一个返回 '2014-12-27 17:30:00 UTC'
的 NSDate NSDateFormatter *dateFormatFixture = [[NSDateFormatter alloc]init];
[dateFormatFixture setDateFormat:@"EEEE d MMMM YYYY HH:mm"];
[dateFormatFixture setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en-GB"]];
[dateFormatFixture setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
NSDate *fixtureDate = [[NSDate alloc] init];
fixtureDate = [dateFormatFixture dateFromString:currentFixture.timeDate];
EEEE d MMMM yyyy H:m 有效,感谢 maddy