I've read through the various posts on SO about this, but have still not solved the problem.
Here's the string that I'm trying to parse into an NSDate
object:
2012-04-08T12:00:00.00+02:00
I understand that the problem is the time zone format. Here's the date format string that I'm trying:
yyyy-MM-dd'T'HH:mm:SSZZZZ
Thanks for any help.
Three things:
Use the -[NSDateFormatter getObjectValue:forString:range:error:] method to learn how much of the string was parsed and what error prevented parsing further.
The ZZZZ format string corresponds to something like "GMT+02:00", with that "GMT" in there. You may need to inject that into the string you're parsing for it to work.
Apple's Data Formatting Guide advises "Consider Unix Functions for Fixed-Format, Unlocalized Dates".
Now the dedicated NSISO8601DateFormatter is available.
来源:https://stackoverflow.com/questions/10057456/parsing-iso-8601-with-nsdateformatter