Reputation: 212
Okay, i already have been going through about 20 threads. I checked everything locale, timezone, whatever .. Nothing.
I tried to Copy whole Snippets where the people said they are working but they aren't working for me ?!
This comes from the Server: 2015-02-25T21:48+02:00
I did the following. I have a UIViewController and In the ViewDidLoad I do the following:
mDateFormat = [[NSDateFormatter alloc] init];
[mDateFormat setDateFormat:@"yyyy-MM-dd'T'HH:mmZZZ"];
And later on in the TableView I try to get the String out of a NSDate. And really looked into it and it is surely a NSDate and not an NSString.
date = [mDateFormat stringFromDate:order.date];
NSLog(date);
NSLog([order.date description]);
NSDate *dd = [mDateFormat dateFromString:@"2014-10-15T00:00+02:00"];
NSLog([dd description]);
Date is a NSString and date is always nil.
The NSLog from order.date returns: 2015-02-25T21:57+01:00 The NSLog from dd returns: 2014-10-14 22:00:00 +0000
I don't know how to solve this. I am already working 1-2 Hours on it. :(
Upvotes: 0
Views: 398
Reputation: 86
I've faced a similar issue with NSDateFormatter on iOS8. When trying to retrieve a NSDate with dateFromString, nil is always returned. It's all about iOS Region Format setting. Change that to another region then back to your region settings. That might be a bug on iOS8.
Upvotes: 0
Reputation: 92306
Your format is wrong. See the Unicode Technical Standard #35-31 which is the one used by iOS 7 and above.
ZZZ
is a format like -0800
(without the :
). You want ZZZZZ
(5 Z) to support the colon, as in -08:00
. So the correct format should be:
[mDateFormat setDateFormat:@"yyyy-MM-dd'T'HH:mmZZZZZ"];
Upvotes: 1