格式化 NSDate
我正在从 RSS 提要中提取数据。 feed 中的键之一是表示项目创建日期和时间的字符串。
我正在尝试将此字符串值转换为 NSDate。从 RSS 提要返回的字符串值如下: 2009-11-18T22:08:00+00:00
我尝试了以下代码但无济于事:
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyyMMdd HH:mm"];
NSDate *myDate = [df dateFromString: [[storedDates objectAtIndex:indexPath.row] objectForKey: @"UsersDate"]];
理想情况下;除了将该值转换为 NSDate 值之外,我还想使用手机上的本地化日期格式对其进行格式化。
任何指示都会有很大的帮助。
亲切的问候
I am pulling data from an RSS Feed. One of the keys in the feed is is a string representing the date and time the item was created.
I am trying to convert this string value to an NSDate. The string value is returned from the RSS feed as: 2009-11-18T22:08:00+00:00
I tried the following code to no avail:
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyyMMdd HH:mm"];
NSDate *myDate = [df dateFromString: [[storedDates objectAtIndex:indexPath.row] objectForKey: @"UsersDate"]];
Ideally; on top of converting the value to a NSDate value, I would also like to format it using the localised date format on the handset.
Any pointers would be a great help.
Kind Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检索 dateFormat:
如果您想根据用户的区域设置设置时间和日期的格式,则可以使用预定义的格式:
查看文档以了解哪种格式化程序最适合您。
To retrieve the dateFormat:
You can use the predefined formats if you would like to format time and date according to the user's locale:
Check the documentation to see which formatter suits you best.
实际上 RSS feed 中的日期形式可能有所不同,因此解析它的最佳方法如下
这不是标准函数,可以在此处找到它的库 https://gist.github.com/953664
Actually date form in RSS feed may differ, so best way to parse it is following
This is not a standard function, library for it can be found here https://gist.github.com/953664