我尝试让我的NSDateFormatter
将其语言环境设置为德语,但它失败了。在下面的代码中,dateFrom
成功解析后,dateTo
不是。
注意:德语是Februar,而不是二月。
NSLocale *germanLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"de_DE"];
NSString *formatString = [NSDateFormatter dateFormatFromTemplate:@"dd. MMMM" options:0
locale:germanLocale];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:formatString];
NSDate *dateFrom = [dateFormat dateFromString:@"20. September"];
NSDate *dateTo = [dateFormat dateFromString:@"20. Februar"];
答案 0 :(得分:2)
尝试设置NSDateFormatter的语言环境:
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
dateFormat.locale = germanLocale;
[dateFormat setDateFormat:@"dd. MMMM"];
NSDate *dateFrom = [dateFormat dateFromString:@"20. September"];
NSDate *dateTo = [dateFormat dateFromString:@"20. Februar"];