Why is this ...
NSString *mydate = @"2011-07-20T23:59:00-07:00"
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];
NSLog(@"%@", [[dateFormatter dateFromString:mydate] description]);
... returning "(null)" in the console?
Your date format of @"yyyy-MM-dd'T'HH:mm:ss'Z'"
means that it's looking for a literal "Z
" character at the end of the string. However, your string is:
@"2011-07-20T23:59:00-07:00"
I don't see a "Z
" there, do you? Thus, the date comes back as nil
because your string does not match the format specified.
According to the Date Formatting Patterns documentation, you're probably looking for the format string of:
@"yyyy-MM-dd'T'HH:mm:ssZZ"
However, even that might not work, because if you notice your source string has a colon (":
") in between the hours and minutes of the timezone offset. There's no timezone specifier that accounts for that. If that is indeed the format in which ROR is returning the date, then ROR is wrong.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With