1

有人知道如何将日期时间从英语转换为西班牙语吗?

例如转换:

December 07, 10:42AM

进入

Diciembre 07, 10:42AM

请帮我。如何转换这个?

提前致谢。

我试过这个:

 NSLocale *frLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"es"] autorelease];
 NSLog(@"%@", [frLocale displayNameForKey:NSLocaleIdentifier value:@"December 07, 10:42AM"]);
 // Value comes Null
4

1 回答 1

3

像下面这样尝试它会有所帮助

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
    [dateFormatter setDateFormat:@"MMMM dd',' hh:mma"];
    NSDate *dateTmp  = [dateFormatter dateFromString:@"December 07, 10:42AM"]; // getting date from string with english locale
    [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"es"]];
    [dateFormatter setAMSymbol:@"AM"]; // default AM symbol for spanish is a.m.
    [dateFormatter setPMSymbol:@"PM"]; // default PM symbol for spanish is p.m.
    NSString *strDate = [dateFormatter stringFromDate:dateTmp]; // getting string from date with spanish locale
    NSLog(@"%@",strDate);
于 2012-12-07T05:53:55.297 回答