[ad_1]
I wish to convert a string to a date, after which return a string once more.
I did this extension, however after I use it it would not work because it ought to.
For instance if I’ve “2020-12-10” the consequence must be “10 de Diciembre de 2020”, nonetheless I at all times get the identical consequence “22 de Diciembre de 2021” and its not appropriate.
That is my code:
extension String {
func dateFormatter(fashion: DateFormatter.Model) -> String? {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd"
formatter.timeZone = .present
formatter.dateStyle = fashion
formatter.locale = Locale(identifier: "es_AR")
return formatter.string(from: Date())
}
}
let dateExample = "2022-09-08" // This must be "8 de Septiembre de 2022"
let dateFormat = dateExample.dateFormatter(fashion: .lengthy) // right here i get "22 de diciembre de 2021"
[ad_2]
