NSDataDetector为英语以外的语言返回错误的日期

时间:2016-02-25 16:43:12

标签: ios objective-c cocoa nsdate nsdatadetector

所以我使用NSDataDetector来获取不同语言的日期。它返回正确的英语日期,但对于其他语言,返回的日期是当前日期。这是代码。

NSString *dateEn = @"Added on Wednesday, February 4, 2015 5:58:18 PM";
NSString *dateStringRussian = @"Добавлено: суббота, 26 декабря 2015 г. в 0:16:57";
NSString *dateStringPortuguese = @"Adicionado: sábado, 26 de dezembro de 2015 11:39:53";

__block NSDate *dateFromDetector;
NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeDate error:nil];
[detector enumerateMatchesInString:dateStringPortuguese options:kNilOptions range:NSMakeRange(0, [dateStringPortuguese length]) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
    dateFromDetector = result.date;    
}];

NSLog(@"date is %@", dateFromDetector);
  

输出葡萄牙语:2016-02-25 22:04:18.530 DateDetector [1681:56498]日期是2016-02-25 18:09:53 +0000

     

输出俄语:2016-02-25 22:14:03.416 DateDetector [1725:60212]日期是2016-02-24 18:46:57 +0000

     

输出英文:2016-02-25 22:12:13.123 DateDetector [1712:59498]日期是2015-02-04 12:28:18 +0000

这里有什么问题?

0 个答案:

没有答案