У меня есть следующий код:NSDateFormatter dateFromString возвращает дату с неправильным месяцем
for (i=0; i<json.count; i++) {
NSDictionary *bodyDictionary = [json objectAtIndex:i];
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
[formatter setLocale:[NSLocale currentLocale]];
[formatter setDateFormat:@"yyyy-mm-dd HH:mm:ss"];
NSDate *date = [formatter dateFromString:[bodyDictionary objectForKey:@"date"]];
NSNumber* thisVolume = [NSNumber numberWithInteger:[[bodyDictionary objectForKey:@"volume"] integerValue]];
NSTimeInterval timeNumber = [date timeIntervalSince1970];
CGPoint point = CGPointMake(timeNumber, thisVolume.doubleValue);
NSValue *pointValue = [NSValue valueWithCGPoint:point];
[dataArray addObject:pointValue];
}
Где перебирать массив словаря объектов - один из которых является дата. Я проверил формат входящей строки даты - что:
2020-07-15 07:01:00
Однако - как только он прошел через dateformatter - NSDate выходит как:
2020-01-15 07:01:00
Несвязанный, но вместо '[NSLocale currentLocale]' вы, вероятно, захотите использовать '[NSLocale localeWithLocaleIdentifier: @" en_US_POSIX "]'. См. [Apple Technical Q & A # 1480] (https://developer.apple.com/library/ios/qa/qa1480/_index.html). – Rob