ios - 如何将任何语言的日期转换为特定语言

标签 ios nsdateformatter nslocale

如何将任何语言(阿拉伯语)的日期转换为特定语言(英语)。

将区域格式更改为阿拉伯语时,日期也更改了。当我从某些控件(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/

相关文章:

ios - VerificationController 突然停止为所有应用程序工作

ios - 调用 UIPinchGestureRecognizer 后更改 UIView 的边界

ios - 如何使用函数dequeueReusableCellWithIdentifier :forIndexPath?

ios - 某些日期的 NSDateformatter 问题

swift - TestFlight 安装后 NSDate() 不返回 UTC +000

IOS:从字符串中解析日期

ios - NSLocale preferredLanguages仅以2个字符作为返回值

ios - 流媒体播放的实时音频效果

iOS - 在不使用 CLLocationManager 的情况下确定用户的国家

iphone - cocoa touch 显示屏 多种货币