If you can live with Yesterday at 21:51
rather than Yesterday, 21:51
create a date formatter and enable doesRelativeDateFormatting
let outputFormatter : DateFormatter = {
let formatter = DateFormatter()
formatter.locale = Locale(identifier: "en_GB")
formatter.doesRelativeDateFormatting = true
formatter.dateStyle = .medium
formatter.timeStyle = .short
return formatter
}()
and create a function to convert the ISO8601 string
func convertISODate(_ isoString : String) -> String {
let formatter = ISO8601DateFormatter()
guard let date = formatter.date(from: isoString) else { return "Unknown date format" }
return outputFormatter.string(from: date)
}
and use it
TableColumn("Last updated"){
Text(convertISODate($0.updated_at))
}
However I would put the entire conversion code into the model.
Side note: doesRelativeDateFormatting
does not work with a custom date format specified in the dateFormat
property.