把
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
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);