I’m trying to transform @"Fri, 26 Aug 2011 10:51:00 +02:00" into an NSDate:
[dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss Z"];
NSDate *date = [dateFormatter dateFromString:dateString];
I get nil as a result; what am I doing wrong?
The colon in the timezone
(+02:00)is the issue. According to the Unicode Standard #35, 1..3 capital Z pattern denotes a RFC 822 time zone. RFC 822 time zones represent the offset from GMT (or UTC) and have the following format:As you can see, there is no colon between hours and minutes of the time zone. Therefore, the time zone should be
+0200.The most proper solution would be to generate a unicode compliant date string in the first place, but if you are stuck with this format, you may need to preprocess the date string before you pass it to
NSDateFormatter.For example, a quick fix would be using
stringByReplacingOccurrencesOfStringto get rid of the colon in the time zone: