I'm trying to parse a date from a JSON object that is in type string. The format is as follows: "2019-12-04 00:00:00". I am trying to convert it using the following code but, it always returns the default optional value (i.e it fails to convert it), and I have no idea why.
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
dateFormatter.dateStyle = .short
dateFormatter.timeStyle = .short
let articleDate = dateFormatter.date(from: "\(sectionsNews.News!.created)") ?? Foundation.Date()
print("\(articleDate)"