NSDate 格式 [英] NSDate Formatting

查看:56
本文介绍了NSDate 格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个日期字符串,如下所示:Fri, 17 Jun 2011 19:20:51 PDT",我需要将其解析为 NSDate 格式.

I have a date string as follows: "Fri, 17 Jun 2011 19:20:51 PDT" which I need to parse into an NSDate format.

 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
 [dateFormatter setDateFormat:@"EEE, d MM YYYY HH:mm:ss zzz"];
 NSDate *date = [dateFormatter dateFromString:currentPubDate ];
 [dateFormatter release];

代码似乎不起作用,我不知道为什么.我已经调查过这个问题,但在论坛等中搜索,似乎找不到答案.我确实相信这是 dateFormatter 的问题.感谢您的帮助

The code doesn't appear to be working and I am not sure why. I have looked into the issue but searching through forums etc and can't seem to find an answer. I do believe it is an issue with the dateFormatter. Thanks for your help

推荐答案

您错误地指定了 setDateFormat 字符串.这是您应该如何指定它:

You incorrectly specified your setDateFormat string. This is how you should have specified it:

[dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss zzz"];

YYYY 仅用于某些工业和商业应用的星期日期"格式.它看起来像这样:YYYY-Www-D 其中 2011-W1-3 相当于 2011 年第一周的第三天.

YYYY is only used in the "Week date" format used for some industrial and commercial applications. It looks like this: YYYY-Www-D where 2011-W1-3 would equate to the third day of the first week of 2011.

Apple 文档指出使用 YYYY 而不是 yyyy 是一个常见错误:固定格式

The Apple docs note that it is a common mistake to use YYYY instead of yyyy: Fixed Formats

这篇关于NSDate 格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆