I have a JSON object that has a mySQL datetime inside of it that I need to decode in Swift and compare it to another date. How can I convert this mySQL datetime into a Swift date?
Below is what is returned in the JSON object:
{"startDate": "Sun, 02 Aug 2020 00:00:00 GMT"}
This is how we've tried to decode it:
struct jsonDate: Codable {
let startDate: String
}
let tempDate = try JSONDecoder().decode(jsonDate.self, from: data)
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
let previousSunday = dateFormatter.date(from: tempDate.startDate)!