Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.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
在iOS 13问题中,NSDateFormatter dateFromString返回nil_Ios_Objective C_Nsdateformatter - Fatal编程技术网

在iOS 13问题中,NSDateFormatter dateFromString返回nil

在iOS 13问题中,NSDateFormatter dateFromString返回nil,ios,objective-c,nsdateformatter,Ios,Objective C,Nsdateformatter,在iOS v13更新之前,NSDateFormatter dateFromString返回了NSDate对象。但在iOS v13和v13.1中,它返回nil NSDate对象。如何解决这个问题 从“设置->常规->日期和时间”更改日期和时间,然后取消选中24小时时间可以解决此错误 NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]

在iOS v13更新之前,NSDateFormatter dateFromString返回了NSDate对象。但在iOS v13和v13.1中,它返回nil NSDate对象。如何解决这个问题

从“设置->常规->日期和时间”更改日期和时间,然后取消选中24小时时间可以解决此错误

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

NSDate *date = [formatter dateFromString:@"2019-10-02 09:10:15"];
应为非零*日期

iOS v12和旧版本没有此问题,设置区域设置不是格式化日期所必需的


我找到了解决这个问题的方法

[formatter setLocale:[NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]];
@hyd00以您的方式设置区域设置也可以解决此问题。非常感谢

[formatter setLocale:[NSLocale localeWithLocaleIdentifier:[NSLocale currentLocale].localeIdentifier]];

我找到了解决这个问题的方法

[formatter setLocale:[NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]];
@hyd00以您的方式设置区域设置也可以解决此问题。非常感谢

[formatter setLocale:[NSLocale localeWithLocaleIdentifier:[NSLocale currentLocale].localeIdentifier]];

如果取消勾选24小时解决了错误,请使用“hh”将小时单位替换为
hh
@Desdenova,在下午时间的输出中显示错误的时间(例如:2019-10-01 14:36:56)。您的代码在iOS 13.1上对我有效。向日期格式化程序添加区域设置,如
[格式化程序设置区域设置:[NSLocale localeWithLocaleIdentifier:[NSLocale currentLocale].localeIdentifier]]
@Paulw11在“设置”中时间格式未设置为“24小时时间”时工作正常如果取消勾选24小时可修复错误,请将您的小时单位替换为
hh
@Desdenova使用“hh”在下午时间的输出中显示错误时间(例如:2019-10-01 14:36:56)。您的代码在iOS 13.1上对我有效。在日期格式化程序中添加区域设置,如
[formatter setLocale:[NSLocale localeWithLocaleIdentifier:[NSLocale currentLocale].localeIdentifier]];
@Paulw11如果“设置”中的时间格式未设置为“24小时时间”,则可以正常工作