Error while converting C# date string into swift3 date

南楼画角 提交于 2019-12-25 19:09:08

问题


In one of my app i am getting date from an RESTful api as "04112017182149".

I tried to convert it into swift date for my internal user as shown in below snippet.

let receivedDate = "04112017182149"
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd" 
print((dateFormatter.date(from: receivedDate))!)

It is throwing a fatal error as Unexpectedly found nil while unwrapping optional value.

I had tried to change date formatter string as "dd-MMM-yyyy HH:mm:ss" but no use.


回答1:


The correct date format is

ddMMyyyyHHmmss


来源:https://stackoverflow.com/questions/47120558/error-while-converting-c-sharp-date-string-into-swift3-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!