问题
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