Unable to Parse Date using NSDateFormatter

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....

Answers


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


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.


Need Your Help

android : how to align message in alertDialog?

android

i have to align text by middle in android alertdialog.

TCP Socket no connection timeout

networking tcp network-programming timeout

I open a TCP socket and connect it to another socket somewhere else on the network. I can then successfully send and receive data. I have a timer that sends something to the socket every second.