Ios 从中文到英文的iPhone日期格式
从我的区域设置中,我在iPhone中获得了中文日期,我需要使用NSDateFormatter将其转换为英文。我尝试过使用下面的代码,但在回应中,我也得到了中文单词Ios 从中文到英文的iPhone日期格式,ios,iphone,objective-c,nsdate,Ios,Iphone,Objective C,Nsdate,从我的区域设置中,我在iPhone中获得了中文日期,我需要使用NSDateFormatter将其转换为英文。我尝试过使用下面的代码,但在回应中,我也得到了中文单词 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh-Hans"]]; [dateFormatter setDat
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh-Hans"]];
[dateFormatter setDateFormat:@"yyyy年MM月dd日'"];
NSDate *dateTmp = [dateFormatter dateFromString:@"2014年3月14日"]; // getting date from string with english locale
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
NSString *strDate = [dateFormatter stringFromDate:dateTmp]; // getting string from date with spanish locale
NSLog(@"%@",strDate);
这是2014年的产量年3.月14日, 不过,我不需要中文。你还必须给出英文的日期格式,如下所示
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh-Hans"]];
[dateFormatter setDateFormat:@"yyyy年MM月dd日'"];
NSDate *dateTmp = [dateFormatter dateFromString:@"2014年3月14日"]; // getting date from string with english locale
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSString *strDate = [dateFormatter stringFromDate:dateTmp]; // getting string from date with spanish locale
NSLog(@"Your OUTPUT IS : %@",strDate);
您的输出为:2014-03-14您还必须提供以下英文日期格式
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh-Hans"]];
[dateFormatter setDateFormat:@"yyyy年MM月dd日'"];
NSDate *dateTmp = [dateFormatter dateFromString:@"2014年3月14日"]; // getting date from string with english locale
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSString *strDate = [dateFormatter stringFromDate:dateTmp]; // getting string from date with spanish locale
NSLog(@"Your OUTPUT IS : %@",strDate);
您的输出为:2014-03-14您还必须提供以下英文日期格式
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh-Hans"]];
[dateFormatter setDateFormat:@"yyyy年MM月dd日'"];
NSDate *dateTmp = [dateFormatter dateFromString:@"2014年3月14日"]; // getting date from string with english locale
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSString *strDate = [dateFormatter stringFromDate:dateTmp]; // getting string from date with spanish locale
NSLog(@"Your OUTPUT IS : %@",strDate);
您的输出为:2014-03-14您还必须提供以下英文日期格式
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh-Hans"]];
[dateFormatter setDateFormat:@"yyyy年MM月dd日'"];
NSDate *dateTmp = [dateFormatter dateFromString:@"2014年3月14日"]; // getting date from string with english locale
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSString *strDate = [dateFormatter stringFromDate:dateTmp]; // getting string from date with spanish locale
NSLog(@"Your OUTPUT IS : %@",strDate);
您的输出是:2014-03-14尝试以下代码
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh-Hans"]];
[dateFormatter setDateFormat:@"yyyy年MM月dd日'"];
NSDate *dateTmp = [dateFormatter dateFromString:@"2014年3月14日"]; // getting date from string with english locale
NSDateFormatter *dateFormatter2 = [[NSDateFormatter alloc] init];
[dateFormatter2 setDateFormat:@"yyyy MM dd'"];
[dateFormatter2 setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
NSString *strDate = [dateFormatter2 stringFromDate:dateTmp]; // getting string from date with spanish locale
NSLog(@"%@",strDate);
尝试以下代码
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh-Hans"]];
[dateFormatter setDateFormat:@"yyyy年MM月dd日'"];
NSDate *dateTmp = [dateFormatter dateFromString:@"2014年3月14日"]; // getting date from string with english locale
NSDateFormatter *dateFormatter2 = [[NSDateFormatter alloc] init];
[dateFormatter2 setDateFormat:@"yyyy MM dd'"];
[dateFormatter2 setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
NSString *strDate = [dateFormatter2 stringFromDate:dateTmp]; // getting string from date with spanish locale
NSLog(@"%@",strDate);
尝试以下代码
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh-Hans"]];
[dateFormatter setDateFormat:@"yyyy年MM月dd日'"];
NSDate *dateTmp = [dateFormatter dateFromString:@"2014年3月14日"]; // getting date from string with english locale
NSDateFormatter *dateFormatter2 = [[NSDateFormatter alloc] init];
[dateFormatter2 setDateFormat:@"yyyy MM dd'"];
[dateFormatter2 setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
NSString *strDate = [dateFormatter2 stringFromDate:dateTmp]; // getting string from date with spanish locale
NSLog(@"%@",strDate);
尝试以下代码
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh-Hans"]];
[dateFormatter setDateFormat:@"yyyy年MM月dd日'"];
NSDate *dateTmp = [dateFormatter dateFromString:@"2014年3月14日"]; // getting date from string with english locale
NSDateFormatter *dateFormatter2 = [[NSDateFormatter alloc] init];
[dateFormatter2 setDateFormat:@"yyyy MM dd'"];
[dateFormatter2 setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
NSString *strDate = [dateFormatter2 stringFromDate:dateTmp]; // getting string from date with spanish locale
NSLog(@"%@",strDate);
您可以使用下一种方法根据模板获取本地化格式:
NSString *neededFormat = [NSDateFormatter dateFormatFromTemplate:@"MMMM dd, yyyy" options:0 locale:[NSLocale currentLocale]];
您可以使用下一种方法根据模板获取本地化格式:
NSString *neededFormat = [NSDateFormatter dateFormatFromTemplate:@"MMMM dd, yyyy" options:0 locale:[NSLocale currentLocale]];
您可以使用下一种方法根据模板获取本地化格式:
NSString *neededFormat = [NSDateFormatter dateFormatFromTemplate:@"MMMM dd, yyyy" options:0 locale:[NSLocale currentLocale]];
您可以使用下一种方法根据模板获取本地化格式:
NSString *neededFormat = [NSDateFormatter dateFormatFromTemplate:@"MMMM dd, yyyy" options:0 locale:[NSLocale currentLocale]];