I'm currently trying to call an Api which then returns me some information along with a change date. Afterwards I want to display the Date in the format "dd.MM.yyyy". The Date I get from the Api looks like this: "2020-03-20T19:30:00". Therefore, I used the solution in this question: How to get time from YYYY-MM-dd'T'HH:mm:ss.sssZ to make it look like the format I want.
Unfortunally when I try to parse the date which I get from the Api I always get a nil value.
The code I wrote looks as follows:
let inputFormatter : DateFormatter = DateFormatter()
inputFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
let dateFormatter : DateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd.MM.yyyy"
//date is always nil
let date = inputFormatter.date(from: content?.DateTime ?? "2020-03-20T19:30:00")
dateLabel.text = dateFormatter.string(from: date ?? Date())
Does somebody know why I always get a nil value and if the way I'm converting the dates is a good/bad practice?