I know you said you don't want it in a string format, however you can simply convert it over after to a date object.
you're welcome to use this, i created this function based on my own string format, change that to whatever you need and boom. enjoy
//this function will allow you to easily convert your date string into readable current context
func convertDateToNow(createdAt:String) -> String{
//create a date to represent the seconds since the start of the internet
let currentDate = Date().timeIntervalSince1970
//create a dateformatter
let dateFormatter = DateFormatter()
//use the locale on the device to set the the related time
dateFormatter.locale = Locale.current
//set the formate of which our date will be coming in at
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
//create a created at date for the post based off its createdAt date and get the seconds since the start of the internet
let createdDate = dateFormatter.date(from: "\(createdAt)")?.timeIntervalSince1970
//now we are left with two values depending on age of post either a few thousands off or it could be years in seconds. so we minus the current date on the users phone seconds from the created date seconds and voilla
let secondsDifference = currentDate - createdDate!
//use our specially created function to convert the seconds difference into time values
let (d,h,m,s) = secondsToHoursMinutesSeconds(seconds: Int(secondsDifference))
//test the values
// print("d:",d)
// print("h:",h)
// print("m:",m)
// print("s:",s)
//
//this will hold the final output of the string
var finalDateLabel:String!
//set the datelabel on the cell accordingly
//create arithmetic for the date features
if d != 0 {
//check to see if the label is a day old
if d == 1 {
finalDateLabel = "\(d) day ago"
}
}else if h != 0{
//set the date label
finalDateLabel = "\(h) hour ago"
if h == 1 {
finalDateLabel = "\(h) hour ago"
}else if h >= 2 {
finalDateLabel = "\(h) hours ago"
}
}else if m != 0{
//set the date label
finalDateLabel = "\(m) minutes ago"
if m == 1 {
finalDateLabel = "\(m) minute ago"
}
}else if s != 0{
//set the date label
finalDateLabel = "\(s) seconds ago"
if s == 1 {
finalDateLabel = "\(s) second ago"
}
}
return finalDateLabel
}
//to help convert the story
func secondsToHoursMinutesSeconds (seconds : Int) -> (Int ,Int, Int, Int) {
return (seconds / 86400, seconds / 3600, (seconds % 3600) / 60, (seconds % 3600) % 60)
}