Ios 如何将任何语言的日期转换为特定语言
如何将任何语言(阿拉伯语)的日期转换为特定语言(英语) 在将区域格式更改为阿拉伯语的同时,日期也在更改。当我从一些控件(UIButtons或UILabels)中选择日期值以保存在数据库中时,它会选择阿拉伯语的日期并以相同的格式保存。在这里,我想将日期从阿拉伯语转换为英语,然后再保存到数据库中 我试过了,但结果是零Ios 如何将任何语言的日期转换为特定语言,ios,nsdateformatter,nslocale,Ios,Nsdateformatter,Nslocale,如何将任何语言(阿拉伯语)的日期转换为特定语言(英语) 在将区域格式更改为阿拉伯语的同时,日期也在更改。当我从一些控件(UIButtons或UILabels)中选择日期值以保存在数据库中时,它会选择阿拉伯语的日期并以相同的格式保存。在这里,我想将日期从阿拉伯语转换为英语,然后再保存到数据库中 我试过了,但结果是零 NSDate *currentDate = //My date coming like “٢٠١٤-٠٥-١٥ ١٢:١٠:٢٣ ” NSDateFormatter *formatt
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];
有人能帮我吗?你不应该用任何语言存储日期。您应该存储NSDate,它没有语言、区域设置或时区,并根据需要显示它。如果您的数据库无法存储NSDate,则可以存储[myDate timeIntervalSince1970],并使用类方法dateWithTimeIntervalSince1970将其转换为NSDate:您不应以任何语言存储日期。您应该存储NSDate,它没有语言、区域设置或时区,并根据需要显示它。如果您的数据库无法存储NSDate,则可以存储[myDate timeIntervalSince1970],并使用类方法dateWithTimeIntervalSince1970将其转换为NSDate:您应该使用UIDatePicker作为输入,而不是UIButtons或UILabel。将时间间隔保存到数据库中,以便可以用任何语言显示
NSDate*currentDate=//我的约会像“٠٠٠-٠-١:٠:٣”
NSTimeInterval timeToBeSavedInDatabase=[currentDate TimeIntervalnces1970];
//将来,您可以用任何语言显示此日期
NSString*dateString=[formatter stringFromDate:[NSDate DateWithTimeIntervalence1970]];
您应该使用UIDatePicker作为输入,而不是UIButton或UILabel。将时间间隔保存到数据库中,以便可以用任何语言显示
NSDate*currentDate=//我的约会像“٠٠٠-٠-١:٠:٣”
NSTimeInterval timeToBeSavedInDatabase=[currentDate TimeIntervalnces1970];
//将来,您可以用任何语言显示此日期
NSString*dateString=[formatter stringFromDate:[NSDate DateWithTimeIntervalence1970]];
我就是这样解决的
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];
我就是这样解决的
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];
您可以使用此选项获取首选本地服务的日期
NSDate * dateNow = [NSDate new];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[dateFormat setLocale: usLocale];
[dateFormat setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSString * dateString = [dateFormat stringFromDate:dateNow];
您可以使用此选项获取首选本地服务的日期
NSDate * dateNow = [NSDate new];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[dateFormat setLocale: usLocale];
[dateFormat setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSString * dateString = [dateFormat stringFromDate:dateNow];
谢谢你的回复,谢谢你的回复