Reputation: 3438
The conversion from string to date keeps returning nil:
if let dateString = dict["dateScanned"] as? String {
let strTime = dateString // 9/5/2017 12:00:00 AM
let formatter = DateFormatter()
formatter.dateFormat = "MM/dd/yyyy HH:mm:ss"
let myDate = formatter.date(from: strTime) // myDate = nil
print(myDate)
}
Upvotes: 0
Views: 184
Reputation: 3176
You are missing the AM/PM information:
formatter.dateFormat = "MM/dd/yyyy hh:mm:ss a"
(and you have to use lower case hh, as pointed out by vadian)
Upvotes: 1