Updated iPad to iOS 15.4.
Now String to Date conversion using DateFormatter returns nil when stored month format "MMM" = Sep.
Works ok when MMM Month = Sept.
Did work in iOS 15.3 and earlier.
Issue is that I have dates created and stored as dd-Sep-2021.
let dateFormat = "dd-MMM-yyyy"
let dateFormatter = DateFormatter()
dateFormatter.calendar = Calendar(identifier: .iso8601)
dateFormatter.dateFormat = dateFormat
let startDate = dateFormatter.date(from: appStartDate) //Returns nil if “11-Sep-2021” and crashes
print(String(describing: startDate))
Did some investigation with this code and found that Sept works and Sep doesn't.
let x = "-Sep-2021" // This returns nil
//let x = "-Sept-2021" // This works
var z: String = ""
let i = 1...30
for n in i {
z = String(n) + x
guard let y = dateFormatter.date(from: z) else {
print(String(n)) // will print if nil
continue
}
print(\(String(describing: y))) //will print if string converted to date
}
All other 3 character month formats work.
Any idea if things have changed?
Locale
of the date formatter toen_US_POSIX
when dealing with custom date formats. And did you try the.gregorian
calendar too? – AffianceddateFormatter.locale = Locale(identifier: "en_US_POSIX")
and it worked. Cheers. – Bullhorn