gpt4 book ai didi

ios - NSString 到 NSDate 给出了完全错误的数据(尝试包括时区)

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:13:18 25 4
gpt4 key购买 nike

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

currentFixtures.timeDate 是一个包含“2015 年 8 月 22 日星期六 17:30”的 NSStringfixtureDate 是一个返回 '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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com