Reputation: 2474
To be more precise this is not working for me:
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"YYYY-MM-ddTHH:mm:ssZ"];
NSDate *prevday = [formatter dateFromString:@"2011-04-07T22:00:48Z"];
prevday is returning NIL.
Upvotes: 2
Views: 2235
Reputation: 3038
You need to inserts ticks in the string:
@"YYYY'-'MM'-'dd'T'HH':'mm':'ss'Z'"
Upvotes: 16
Reputation: 3358
According to this document;
Date formatters use the following version of the standard;
http://unicode.org/reports/tr35/tr35-10.html#Date_Format_Patterns
so you'd use the date format 'yyyy-MM-ddTHH:mm:ss' I'm not sure about the Z, is that supposed to be the time zone? Z in the format string will give you the 3 letter time zone name.
Edited based on your edit above:
[formatter setDateFormat:@"YYYY-MM-ddTHH:mm:ssZ"];
Is why it's returning nil.
The 'Z' expects the time zone to be in the 3 character time zone thing...
Drop the Z or escape it with a quote character. Read the tr35 doc above for more info.
Upvotes: 0