Error message:
unexpected number of calendar units: 4 for format: EEE ├'day': d┤ HH.mm (expecting at least 5 elements)
Could you show how you have defined format ?
You should have something like this:
let source = "Mon, 21 Mar 2016 10:26:45 GMT"
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "en_US")
dateFormatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss zzz"
let day = dateFormatter.date(from: source)
print("day", day!)
Or (with just 5 components):
let source = "Thu, 14 Oct 2021 10:26:45"
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "en_US")
dateFormatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss"
let day = dateFormatter.date(from: source2)
print("day", day!)
Take care that the 3 letters for the day of week must correspond to locale:
"Thu" if "en_US"
"Jeu" if "fr_FR"
"Jue" if "es_ES"
It crashes otherwise.
Topic:
App & System Services
SubTopic:
Core OS
Tags: