为什么从字符串创建日期仅在真正的 iphone 上失败? [英] Why create Date from String only failed On Real iphone?
本文介绍了为什么从字符串创建日期仅在真正的 iphone 上失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下函数从字符串创建日期.它在模拟器上运行良好.但它在真正的 iPhone 上崩溃了.
I'm using following function to create Date from String. It works well on simulator. But it crashed on real iPhone.
String: "Tue May 23 23:19:41 +0800 2017"
第一张图为真机调试信息.第二个是模拟器上的调试信息.
The first picture is debugging information on real iPhone. The second one is debugging information on simulator.
func createDate(fromString string: String) -> Date {
let formatter = DateFormatter()
formatter.dateFormat = "EEE MMM dd HH:mm:ss zzz yyyy"
let date = formatter.date(from: string) //fatal error: unexpectedly found nil while unwrapping an Optional value
return date!
}
我什至在操场上试过.真的很奇怪!谢谢!
I even tried it on playground. It's really weird! Thanks!
推荐答案
this link 可能会解决您的问题.....
this link may solve your problem.....
迅捷
formatter.locale = Locale(identifier: "en_US")
这篇关于为什么从字符串创建日期仅在真正的 iphone 上失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文