I have strings like this 2020-09-21T21:13:55.636Z
... I want to convert them into Date
s and here's what I do;
func convertToDate(str: String) -> Date {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
return dateFormatter.date(from: str)!
}
The above code crashes on the unwrapping. I'm guessing it's because of the format... Any idea what I'm doing wrong?