[ad_1]
I must convert 2022-01-20T00:00:00.000Z to “dd MMM yyy” format.
I’ve tried doing it as recommended in a stackoverflow reply nevertheless it returns nil
func convertDate(date:String)-> String{
let dateFormatterGet = DateFormatter()
dateFormatterGet.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
let dateFormatterPrint = DateFormatter()
dateFormatterPrint.dateFormat = "dd MMM yyy"
if let date = dateFormatterGet.date(from: String(dateinString)) {
let convertedDate = dateFormatterPrint.string(from: date)
return convertedDate
} else {
print("There was an error decoding the string")
}
return "nil"
}
Please assist me ,thanks upfront.
[ad_2]
