views:

226

answers:

2

Hi,

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

2010-05-10T06:11:14.000Z

Now i am using NSDateFormatter to parse this datetime stamp.

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

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.

Any idea ?

Thanks in Advance....

A: 

From memory I've had this problem in the past as well. A couple of things to try:

  1. Replace the "T" in your RSS feed with a space (and obviously change the date format string as well).

  2. Your RSS feed has padded digits, where as your format string does not. Give this a try "yyyy-MM-ddTHH:mm:ss.Z". According to this link, that "z" should be capilized. http://www.stepcase.com/blog/2008/12/02/format-string-for-the-iphone-nsdateformatter/

  3. Strip off the timezone info from the RSS feed and parse this manually. I seem to remember this causing problems for me.

alku83
Thanks for the handy link, and also for your suggestion :)
Ansari
+3  A: 

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

You need to escape the literal T as 'T'

You need to parse the fractional part of the seconds with SSS

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'"

Date Format Patterns

drawnonward
Its working perfect, your suggestion really worked, zone is parsed and its returning +0005 now, and T is escaped.Thanks a bunch again. :)
Ansari