Objective c 如何获取本地化的日期单位?

Objective c 如何获取本地化的日期单位?,objective-c,nsdate,Objective C,Nsdate,我需要一个带有日期单位的数组,例如年、月、日。。。。 我希望他们是本地化的,例如在德语中,它将是Jahr,Monat,Tag 似乎我只能从日期获取本地化字符串,但无法获取单位。 有没有办法直接从当前日历中获取这些单位,而不是手工翻译 NSCalendar *gregorian=[[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar]; [gregorian setTimeZone:[NSTimeZone

我需要一个带有日期单位的数组,例如年、月、日。。。。 我希望他们是本地化的,例如在德语中,它将是Jahr,Monat,Tag

似乎我只能从日期获取本地化字符串,但无法获取单位。 有没有办法直接从当前日历中获取这些单位,而不是手工翻译

   NSCalendar *gregorian=[[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
    [gregorian setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"CDT"]];
    NSDateComponents *timeZoneComps=[[NSDateComponents alloc] init];
    [timeZoneComps setHour:16];
    //specify whatever day, month, and year is appropriate
    NSDate *date=[gregorian dateFromComponents:timeZoneComps];
NSDateFormatter *df = [[NSDateFormatter alloc] init];
    NSString *monthName = [[df monthSymbols] objectAtIndex:(mymonth-1)];
    [df setDateFormat:@"EEE"];
   NSString *weekName = [ df stringFromDate:date];
    NSLog(@"The Week Name :: %@",weekName);
    [df release];

您可以使用上面的代码,尤其是
时区的缩写:@“CDT”
表示各种时区的缩写,如CDT、GMT、UTC、CST。据我所知,您需要为这些单元提供自己的翻译。您可以使用NSDateFormatter获取日期和月份的名称,但不能获取单位本身。单元的翻译方式取决于语法大小写和数字,因此翻译是上下文敏感的。别忘了,有些语言不仅仅有单数和复数