With the Cocoa framework how can I parse @"2008-12-29T00:27:42-08:00" into an NSDate object? The standard -dateWithString:
doesn't like it.
相关问题
- Correctly parse PDF paragraphs with Python
- R: eval(parse()) error message: cannot ope
- Date with SimpleDateFormat in Java
- How do I parse a .pls file using PHP? Having troub
- NSOutlineView drag line stuck + blue border
相关文章
- How do I get from a type to the TryParse method?
- MYSQL: How can I find 'last monday's date&
- Calculate number of working days in a month [dupli
- Converting (u)int64_t to NSNumbers
- “getter” keyword in @property declaration in Objec
- Get file created date in node
- Temporal Extraction (i.e. Extract date/time entiti
- NSMenuItem KeyEquivalent “ ”(space) bug
Actually, you need to set timezone, calendar and locale. If you don't set locale, an user has AM/PM time enabled the formatter will add AM/PM marker! If you don't set the timezone, it will use the current timezone, but will mark it as "Z" ("Zulu" or GMT). If you do not set calendar, users with Japanese Imperial calendar will have number of years since current Emperor's ascension instead of the number of years since Jesus Christ was born. Be sure to test in all of the scenarios I mentioned!
If you only need to handle the ISO 8601 format (of which that string is an example), you might try my ISO 8601 parser and unparser.
You can use NSDateFormatter to parse dates:
The unicode date format patterns defines the format string you can use with the
setDateFormat:
method.Note that if you're targeting 10.4 then you need to call:
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
. Not needed for iphone, or leopard as this mode is the default there.How the time zone is set changed from ios 5 to ios 6. iOS 6 supports the format +01:00 using ZZZZZ but ios 5 doesn't. I solved this issue with this solution which worked for me to parse a date with the following format in ios 5 and 6.
2013-05-07T00:00:00+01:00