iOS 15.4 Date Format "Sep" now "Sept"

328 views Asked by At

The app crashes once the user selects any date of September. It only happens with iOS 15.4.

I have datePicker formatted date to return always in UTC format en_GB.

    @objc func doneDateClicked() {

    let dateFormatter = DateFormatter()
    dateFormatter.dateStyle = .medium
    dateFormatter.timeStyle = .none //CHANGED 09.07.2020 date medium time none
    dateFormatter.timeZone = TimeZone(secondsFromGMT: 0)
    dateFormatter.timeZone = TimeZone(identifier: "GMT")
    dateFormatter.locale = Locale(identifier: "en_GB")
    dateFormatter.dateFormat = "dd MMM yyyy"
    let timeFormatter = DateFormatter()
    timeFormatter.dateStyle = .none
    timeFormatter.timeStyle = .medium
    timeFormatter.timeZone = TimeZone(secondsFromGMT: 0)
    timeFormatter.timeZone = TimeZone(identifier: "GMT")
    timeFormatter.locale = Locale(identifier: "en_150")


    dateTextField.text = dateFormatter.string(from: (datePicker?.date )!)
    self.view.endEditing(true)
}

Then I need to covert the selected date from string (dateTextField.text) to date on iOS 15.4 the month September it shows "Sept".

code to convert from string to date

    let formatter = DateFormatter()             
    formatter.locale = Locale(identifier: "en_GB")
    formatter.dateFormat = "dd MMM yyyy hh:mm:ss"
    formatter.calendar = Calendar(identifier: .gregorian)
    let datenN = formatter.date(from: "\(dateTextField.text ?? "") 00:00:00")

datenN crashing the app it returns nil

I tried to use code formatter.locale = Locale(identifier: "en_US_POSIX") but the app still crashing

1

There are 1 answers

0
workingdog support Ukraine On BEST ANSWER

Assuming this problem occurs just for September and on iOS 15.4, then a quick work around, is to replace "Sept" with "Sep", using

 dateTextField.text = dateFormatter.string(from: (datePicker?.date )!)

 if dateTextField.text.contains("Sept") {
     dateTextField.text = dateTextField.text.replacingOccurrences(of: "Sept", with: "Sep")
 }