gpt4 book ai didi

ios - Xcode 日期格式 - 来自 RSS 的格式

转载 作者:行者123 更新时间:2023-11-28 22:03:47 26 4
gpt4 key购买 nike

我总是在这方面遇到麻烦,并且似乎一直在寻找一个很好的资源来详尽地学习这一点。我正在尝试在 Xcode Objective-C 中使用日期格式化程序,但我没有正确设置日期格式。这是我的数据:

Fri, 27 Jun 2014 12:33:18 +0000

有人可以帮助我或指出正确的方向吗?尝试下面的代码,但它不工作。

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
[dateFormatter setDateFormat:@"EEE, d LLL yyyy HH:mm:ss Z"];

更新:下面的格式可能会有所帮助,因为它在当天显示了一些零填充。

Wed, 02 Jul 2014 11:47:35 +0000

最佳答案

根据Unicode Technical Standard #35 ,“LLL”是“独立月份”的日期格式,它是“没有关联日期编号的月份名称”。您应该改用“MMM”:

[dateFormatter setDateFormat:@"EEE, d MMM yyyy HH:mm:ss Z"];

例子:

NSString *str = @"Fri, 27 Jun 2014 12:33:18 +0000";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
[dateFormatter setDateFormat:@"EEE, d MMM yyyy HH:mm:ss Z"];
NSDate *date = [dateFormatter dateFromString:str];
NSLog(@"%@", date);
// Output: 2014-06-27 12:33:18 +0000

关于ios - Xcode 日期格式 - 来自 RSS 的格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24482892/

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