I am given a date:
2012-10-11T23:14:00-04:00
I am using this format for NSDateFormatter to parse:
yyyy-MM-dd'T'HH:mm:ss-ZZ
But it returns nil
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your date format is wrong. If you have a colon in the string you’re converting, you must put 5 Z characters in the format string, that is the correct usage. Also, you’d never include the +/- as part of the format, since you’re not guaranteed to only have dates + or – GMT (at least not when you’re talking about a /format/).
So, the correct format string would be
yyyy'-'MM'-'dd'T'HH':'mm':'ssZZZZZ:Only using two Z characters would be the RFC 822 format, and your date string would have to look like:
2012-10-11T23:14:00-0400(i.e., no hour/minute separator on the time zone offset). The timezone in your example string is ISO-8601. For more information, see: http://www.unicode.org/reports/tr35/tr35-25.html#Date_Format_Patterns