I would like to create an NSDate from a string:
NSString *mostRecentMentionMessageTimestamp = [mostRecentMessage valueForKey:@"updated_at"];
NSLog(@"%@",mostRecentMentionMessageTimestamp);
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
NSDate *mostRecentMentionDate = [dateFormatter dateFromString:mostRecentMentionMessageTimestamp];
NSLog(@"%@",mostRecentMentionDate);
When I print my string it is:
2011-11-10T07:22:59Z
After I make a date from string and print it, it is (null)
What am I doing wrong?
The format is almost correct, use:
to solve the time zone issue use the solution by @Jef add:
Full example code:
NSLog output: