Parsing ISO 8601 with NSDateFormatter

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.

Answers


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.


Need Your Help

EXTJS 4.2 implementing multiple Editor xtypes for RowEditing a grid?

javascript extjs extjs4.2

I'm using Extjs 4.2 and am currently using the RowEditing plugin on a gridpanel so the user can edit records in the grid. The editor xtype for a given column needs to be 'textfield' for all but one

XML Extra free space

c# xml xmldocument

Good day, in general is a problem, I work with XML through C# XMLdocument, after saving that "document", there is such a thing: