DateFormatter returning string with incorrect language
func portugueseFormattedEn_US -> String {
Formatter.date.calendar = Calendar(identifier: .iso8601)
Formatter.date.locale = Locale(identifier: “pt-PT”)
Formatter.date.timeZone = .current
Formatter.date.dateFormat = "dd/M/yyyy, H:mm"
return Formatter.date.string(from: self)
}
in "Locale(identntfier: “pt-PT”)" you have to pass exact identifier which you want and need to set language as well.
As I Understand your question. You want to change the date format with the current device language.
Set Locale as your preferred language
let formatter = DateFormatter()
formatter.timeZone = TimeZone.current
formatter.locale = Locale.init(identifier: Locale.preferredLanguages.first!)
formatter.setLocalizedDateFormatFromTemplate("ddMMMMyyyy HH:mm")
let stringDate = formatter.string(from: Date())
print(stringDate)
Output:- Show date with current device language.
08 de março de 2019 10:54