[ad_1]
I’m making an attempt to transform a string to a date in swift. Nonetheless, it really works on my iPhone and on the simulator however not on different iPhone. Each units has 24h format. I’ve already tried to vary HH to hh.
extension String {
func stringToDate() -> Date {
let dateFormatter = DateFormatter()
// Set Date Format
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
dateFormatter.dateFormat = "dd MMM yyyy HH:mm:ss Z"
// Convert String to Date
return dateFormatter.date(from: self)!
}
}
The string is the same as 18 Apr 2022 01:12:07 +0200 and dateFormatter.date(from: self) return a nil worth. I’ve already seen different comparable questions on this subject, however no considered one of them remedy this downside.
[ad_2]
