OGeek|极客世界-中国程序员成长平台

标题: ios - NSString to NSDate提供了完全错误的数据(尝试包括时区) [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 09:50
标题: ios - NSString to NSDate提供了完全错误的数据(尝试包括时区)

尝试将日期为“2015年8月22日星期六17:30”的NSString转换为NSDate,但其结果为“2014-12-27 17:30:00 UTC”。我什至不在乎格式是否会出错,我只希望它将其正确转换为NSDate。

currentFixtures.timeDate是包含“星期六2015年8月22日17:30”的NSString
FixtureDate是一个NSDate,返回的是“2014-12-27 17:30:00 UTC”

 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];



Best Answer-推荐答案


EEEE d MMMM yyyy H:m的工作,多亏了maddy

关于ios - NSString to NSDate提供了完全错误的数据(尝试包括时区),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31969168/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4