The problem solved by setting the formatter's locale to en_US_POSIX
. It is necessary while parsing fixed-format date strings because the format of the date strings is constant unlike device' locale.
The code should be like
+(NSDate*)dateTimeFromJSONDateString:(NSString*)dateString{
static NSDateFormatter *_dateFormatter;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_dateFormatter = [[NSDateFormatter alloc] init];
_dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
[_dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZ"];
});
if (string)
return [_dateFormatter dateFromString:string];
else
return nil;
}