Has the parsing for timzones changed in iOS8?
I try to parse the date "2014-09-03 12:20:38.000 +0200"
with this code and get nil:
-(NSDateFormatter*) dateAndTimeFormatter{
if(!_dateAndTimeFormatter){
_dateAndTimeFormatter = [[NSDateFormatter alloc]init];
[_dateAndTimeFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS ZZZZZ"];
_dateAndTimeFormatter.dateStyle = NSDateFormatterShortStyle;
_dateAndTimeFormatter.timeStyle = NSDateFormatterShortStyle;
}
return _dateAndTimeFormatter;
}
alternatively
[_dateAndTimeFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS Z"];
doesn't work either.
Setting
dateStyle
ortimeStyle
will override any customdateFormat
you have set. Your date string does not conform in any way toNSDateFormatterShortStyle
, which is why you are getting nil when trying to convert strings to dates.Furthermore, according to Unicode Technical Standard #35 revision 31, the timezone specifier of "ZZZZZ" corresponds to date strings with formats like "-08:00" or "-07:52:58", not "+0200" as you have in your example. One of the specifiers that matches "+0200" is the one with one to three capital "Z" characters.
This should work for you:
Also, note that your code should also not be working prior to iOS 8.