Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

objective c - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...