Update
Like iOS 7, NSDateFormatter does create an NSDate when presenting a string in this format:
NSDateFormatter *formatter = [NSDateFormatter new]; [formatter setDateFormat:@"@"yyyy'-'MM'-'dd'T'HH':'mm':'ssZ""]; NSLog(@"non–nil date, even honoring the 7–minute–offset in the time–zone on iOS 7: %@", [formatter dateFromString:@"2011-07-12T18:07:31+02:07"]);
For iOS 6, the answer is not to use NSDateFormatter ...
Ok, up to this point i read
regarding the use of NSDateFormatter to create an NSDate from a string.
I came across Peter Hosey ISO8601DateFormatter as well. Looking into its implementation, I wonder:
Is there a way that is right and right to get a line like this 2011-07-12T18:07:31+02:00 in NSDate ?
- There would be no problem if the last colon was missing.
- There would be no problems if there was
GMT , the prefix of the "+" sign, but ... - This is not true.
I can hack it to work for my application (using the format @"yyyy'-'MM'-'dd'T'HH':'mm':'ssz':'00" ), but this - of course - is wrong , because that he will discard minute time zone information.
I could also replace the last colon with an empty string, but I would also think it was a hack.
So, is there any secret sauce so that NSDateFormatter takes this line on top and gives me the correct and correct NSDate ?
To the side:
I found a hint somewhere that you can use +[NSDate dateWithNaturalLanguageString:] to achieve my goal. This - however - only sets the date, not the time! (Well, this sets the time, but only considers the time zone offset, not HH: mm: ss part ...)