在iPhone中将DateTime从英文转换成西班牙语? [英] Convert DateTime from English to Spanish in iPhone?
本文介绍了在iPhone中将DateTime从英文转换成西班牙语?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有人知道如何将DateTime从英文转换成西班牙语?
Does anybody know how to convert a DateTime from English to Spanish?
例如转换:
December 07, 10:42AM
into
Diciembre 07, 10:42AM
请帮助我如何转换?
Please help me. How to convert this?
提前感谢
我尝试过:
NSLocale *frLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"es"] autorelease];
NSLog(@"%@", [frLocale displayNameForKey:NSLocaleIdentifier value:@"December 07, 10:42AM"]);
// Value comes 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);
这篇关于在iPhone中将DateTime从英文转换成西班牙语?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文