I have a "createdAt" date string that I want to format like EEEE, MMM d, yyyy in Swift 4.
var createdAt:String = ""
And a function that formats a date
func getFormattedDate(date: Date, format: String) -> String {
let dateformat = DateFormatter()
dateformat.dateFormat = format
return dateformat.string(from: date)
}
I can use this function to correctly format todays date like so:
let formatingDate = getFormattedDate(date: Date(), format: "EEEE, MMM d, yyyy")
Text(formatingDate)
But how do I make it so it correctly formats my "createdAt" string not just todays date?