如何将任何语言(阿拉伯语)的日期转换为特定语言(英语)。
将区域格式更改为阿拉伯语时,日期也更改了。当我从某些控件(UIButtons或UILabels)中选择日期值以保存在数据库中时,它用阿拉伯语选择日期并以相同格式保存。在这里,我想将日期从阿拉伯语转换为英语,然后再将其保存到数据库中。
我尝试了这个,但它返回了零
NSDate *currentDate = //My date coming like “٢٠١٤-٠٥-١٥ ١٢:١٠:٢٣ ”
NSDateFormatter *formatter=[[NSDateFormatter alloc] init];
NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[formatter setLocale: usLocale];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:s a"];
NSString *formattedDate = [formatter stringFromDate: currentDate];
谁能帮帮我吗 ?
最佳答案
我这样解决了
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
[dateFormatter setTimeZone:timeZone];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:s"];
NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[dateFormatter setLocale:usLocale];
NSString *dateString = [dateFormatter stringFromDate:myDate];
关于ios - 如何将任何语言的日期转换为特定语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23680026/