Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone NSDateFormatter未根据区域提供一致的日期_Iphone_Objective C_Nsdateformatter - Fatal编程技术网

Iphone NSDateFormatter未根据区域提供一致的日期

Iphone NSDateFormatter未根据区域提供一致的日期,iphone,objective-c,nsdateformatter,Iphone,Objective C,Nsdateformatter,我试图本地化我的日期,但由于某些原因,它也没有从区域输出正确的格式 这就是它如何测试我的代码: if(dateformater==nil) dateformater =[[NSDateFormatter alloc] init]; [dateformater setLocale:[NSLocale currentLocale]]; [dateformater setDateStyle:NSDateFormatterMediumStyle]; [dateformater setTimeStyle:

我试图本地化我的日期,但由于某些原因,它也没有从区域输出正确的格式

这就是它如何测试我的代码:

if(dateformater==nil)
dateformater =[[NSDateFormatter alloc] init];
[dateformater setLocale:[NSLocale currentLocale]];
[dateformater setDateStyle:NSDateFormatterMediumStyle];
[dateformater setTimeStyle:NSDateFormatterShortStyle];
NSString  *string_date=[dateformater stringFromDate:date];
NSLog(@"Loacle:----%@   Date:----%@",[[NSLocale currentLocale] localeIdentifier],string_date);
下面是一些本地化日期的示例,以及哪里出错

Loacle:----da_DK   Date:----24/11/2011 14.10--------(WRONG)
Loacle:----en_BE   Date:----24 Nov 2011 14:09--------(OK)
Loacle:----nl_BE   Date:----24-nov.-2011 14:10------(WRONG)
Loacle:----fr_BE   Date:----24 nov. 2011 14:11-------(OK)
Loacle:----en_US   Date:----Nov 24, 2011 2:11 PM-----(OK)
Loacle:----en_GB   Date:----24 Nov 2011 14:11--------(OK)

这些要求说明,它应该对所有区域保持一致。

如果您想要相同的输出,则需要使用相同的区域设置,或者使用setDateFormat:。设置区域设置的全部目的是为不同的样式使用不同的格式。

解释为什么错误的行是错误的。我希望loacale en_的方法一致,因为我没有得到分隔符和月份符号,但da_DK我得到了日期分隔符,我得到了11而不是Nov我不想要相同的输出,我需要根据区域设置的日期。也许您需要考虑使用setDateFormat:而不是setDateStyle:和setTimeStyle:。如果我设置了特定的格式,我会遇到更多问题。作为区域设置en_US,我们将获得2011年11月24日下午2:11,对于区域设置en_GB,我们将获得2011年11月24日14:11。日期和月份的顺序可能会更改