无法使用NSDateFormatter解析日期 [英] Unable to Parse Date using NSDateFormatter

查看:147
本文介绍了无法使用NSDateFormatter解析日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在获取RSS,其中我收到以下日期戳:

I am fetching a RSS, in which i receive the following Date stamp:

2010-05-10T06:11:14.000Z

现在我使用NSDateFormatter来解析这个日期时间戳。

Now i am using NSDateFormatter to parse this datetime stamp.

[parseFormatter setDateFormat:@"yyyy-MM-dTH:m:s.z"];

但如果只删除日期工作的时间戳部分 [parseFormatter setDateFormat:@yyyy-MM-d]; 但是如果我添加其余的东西它会返回nil。

But its not working fine if just remove the time stamp part it works for the date [parseFormatter setDateFormat:@"yyyy-MM-d"]; But if i add the rest of the stuff it returns nil.

有什么想法吗?

先谢谢....

推荐答案

你需要为d,H,m,s解析零填充值

You need to parse zero padded values for d, H, m, s

你需要转义文字 T as 'T'

You need to escape the literal T as 'T'

你需要用解析秒的小数部分SSS

您可以使用'接受文字 Z Z'或使用大写字母Z来尝试解析时区,但RSS使用单独的标准。

You can accept a literal Z with 'Z' or use uppercase Z to try and parse the timezone but RSS uses separate standard.

@yyyy- MM-dd'T'HH:mm:ss.SSS'Z'

日期格式模式

这篇关于无法使用NSDateFormatter解析日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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