2 vikeytoy vikeyToy 于 2012.12.07 16:50 提问

将datetime从英语转成西班牙语

December 07, 10:42AM

转为

Diciembre 07, 10:42AM

我写的代码:

NSLocale *frLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"es"] autorelease];
 NSLog(@"%@", [frLocale displayNameForKey:NSLocaleIdentifier value:@"December 07, 10:42AM"]);
 // 获得值为null

1个回答

redCoral_
redCoral_   2012.12.07 17:13
已采纳
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);
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!