三十二,在iOS中[__NSCFCalendar components:fromDate:]: date cannot be nil,日期转换成NSDate对象为nil ,
来源:互联网 发布:ubuntu 修改启动顺序 编辑:程序博客网 时间:2024/05/18 03:58
昨天在日期转换中遇到这么个问题,其他的数据都没有问题,但是19890416出现问题了最后一个群友给了个地址解决了这个问题;
NSString *dateStr = @"19890416";
NSDateFormatter *format = [[NSDateFormatter alloc]init];
[format setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"]];
[format setDateFormat:@"yyyyMMdd"];
NSDate *date = [format dateFromString:dateStr];
最后打印date数据为nil
具体方法如下
如果DateFormatter的时区设置为我国实行了夏令时的城市,19860504、19870412、19880410、19890416、19900415、19910414 这些日期转换成NSDate对象为nil
代码修改方式为:给dateFormatter显示设置时区偏移量
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:3600*8]];
https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSTimeZone_Class/index.html#//apple_ref/occ/clm/NSTimeZone/timeZoneForSeconds
转载自:http://www.amadman.org/blog/2016/08/
谢谢!
- 三十二,在iOS中[__NSCFCalendar components:fromDate:]: date cannot be nil,日期转换成NSDate对象为nil ,
- iOS调试——部分日期字符串转换成NSDate对象为nil处理办法
- NSUserDefaults 中对象为nil和@""
- iOS 中 nil, Nil, NULL 理解区分
- IOS中nil/Nil/NULL的区别
- iOS中nil,Nil,NULL的区别
- ios中NULL nil Nil的区别
- iOS中nil、Nil、NULL、NSNull 区别
- iOS中nil 、NULL、 Nil 、NSNull
- stringByRemovingPercentEncoding 对空字符对象的转化在ios8以下为nil,ios以上为@“”
- '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
- * -[__NSArrayM insertObject:atIndex:]: object cannot be nil
- Dictionary and Array value cannot be nil
- setObjectForKey: object cannot be nil (key: av)'
- setObjectForKey: object cannot be nil (key: UIImagePickerControllerOriginalImage)
- iOS-对象为空的判断(nil、null)
- iOS-对象为空的判断(nil、null)
- iOS-对象为空的判断(nil、null)
- 字体霓虹灯效果
- react 工程化的需求
- 加大JDK内存的设置
- VS2013通过MySQL方式连接到MySQL
- 干掉状态:从session到token
- 三十二,在iOS中[__NSCFCalendar components:fromDate:]: date cannot be nil,日期转换成NSDate对象为nil ,
- 使用Nexus搭建Maven私服
- 设计模式之装饰模式(Decorator)
- 调试时,favicon.ico资源加载失败问题
- json对象和gridView
- SpringBoot MyBatis注解
- 使用Unity中Microphone类进行用户自由时长音频录制
- web.xml中配置error-page
- 多媒体开发相关文章