Parsing ISO 8601 with NSDateFormatter

前端 未结 2 728
耶瑟儿~
耶瑟儿~ 2020-12-20 07:58

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

相关标签:
2条回答
  • 2020-12-20 08:40

    Now the dedicated NSISO8601DateFormatter is available.

    0 讨论(0)
  • 2020-12-20 08:43

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

    0 讨论(0)
提交回复
热议问题