ios - 我为聊天应用程序编写了代码,适用于 iOS 12,但在 iOS 13 中,它返回 nil 值
问题描述
我为聊天应用程序编写了代码,在 iOS 12 上运行良好,在 iOS 13 中,它返回 nil 值。
这是我的 dateformatter 代码片段。
-(NSDate *)stringToDateNew:(NSString*)strDate withForamt:(NSString *)strFormat {
@try
{
NSDate *myDate;
if(strDate!=NULL)
{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:[NSString stringWithFormat:@"%@",strFormat]];
NSLocale * enUSPOSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] ;
if (enUSPOSIXLocale == nil) {
enUSPOSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
}
else
{
[dateFormat setTimeZone:[NSTimeZone systemTimeZone]];
[dateFormat setLocale:enUSPOSIXLocale];
myDate = [dateFormat dateFromString:strDate];
return myDate;
}
}
return NULL;
}
@catch (NSException *exception)
{
NSLog(@"Excption in AppDelegate : stringToDate %@:%@",exception.name,exception.reason);
}
}
解决方案
使用 withformat "yyyy-mm-dd'T'hh:mm:ss.SSS"。它也适用于 os 13。
推荐阅读
- git - 如何压缩已经合并的提交?
- python - Python Selenium,找到一个按钮
- postgresql - 在谷歌 CloudSQL 中备份 PostgresSQL 单个数据库(非实例)的最佳方法是什么
- php - Laravel 为 foreach() 问题提供的参数无效
- android - Android Studio 正确编译项目,Gradlew 没有启用数据绑定
- selenium - selenium chrome驱动程序在c#中选择证书弹出确认
- sharepoint - 将大文件上传到 SharePoint 2016 会挂起整个服务器
- python - 应在至少 2 个输入的列表上调用“连接”层
- time-complexity - 当条件依赖于其他变量时,如何解决单循环复杂性?
- linux - linux bash 和 grep 错误?