Ios 如何在UiTableView中的Xcode上显示Firebase实时数据库的时间戳

Ios 如何在UiTableView中的Xcode上显示Firebase实时数据库的时间戳,ios,xcode,uitableview,firebase,timestamp,Ios,Xcode,Uitableview,Firebase,Timestamp,好吧,这是一个艰难的时刻。我正在用一个提要构建一个社交媒体应用程序,该提要有一个Uitableview,存储在帖子包含的firebase实时数据库中 作者 文字:“嗨” 时间戳:“1532194221795” 我的目标是根据手机发布的时间,以更具吸引力的方式在手机中显示时间戳,例如(15分钟前、2小时前、5天前、2个月前) 我的NewPostViewController中有这个 “时间戳”:[“.sv”:“时间戳”] 在我的提要中保存为双精度,如下所示let timestamp=dict[“ti

好吧,这是一个艰难的时刻。我正在用一个提要构建一个社交媒体应用程序,该提要有一个Uitableview,存储在帖子包含的firebase实时数据库中

作者 文字:“嗨” 时间戳:“1532194221795”

我的目标是根据手机发布的时间,以更具吸引力的方式在手机中显示时间戳,例如(15分钟前、2小时前、5天前、2个月前)

我的NewPostViewController中有这个
“时间戳”:[“.sv”:“时间戳”]

在我的提要中保存为双精度,如下所示
let timestamp=dict[“timestamp”]as?双重{

它通过my PostTableViewCell
subtitlabel.text=“\(post.timestamp)”

我也收集了这样的信息

`func timesinesnowstring()->String { 让calendar=calendar.current

    let components = calendar.dateComponents([.day, .hour, .minute, .second], from: self, to: Date())

    if components.day! >= 365 {
        return "\(components.day! / 365) years ago"
    }

    if components.day! >= 7 {
        return "\(components.day! / 7) weeks ago"
    }

    if components.day! > 0 {
        return "\(components.day!) days ago"
    }
    else if components.hour! > 0 {
        return "\(components.hour!) hours ago"
    }
    else if components.minute! > 0 {
        return "\(components.minute!) minutes ago"
    }
    return "Now"
}

这也是日期(时间间隔自1970年起:createdAt/1000)`


它给我的错误,如表达式的类型是不明确的,没有更多的上下文”的第一部分和“使用未解析的标识符'createdAt'“对于日期的第二部分。有人知道如何在没有这些错误的情况下设置它吗?我将永远爱你,谢谢你的阅读。

只要用
时间戳
更改那些
createdAt
,你已经键入了
Double

这是我的游乐场:

func timeSinceNowString(_ timeInterval:TimeInterval) -> String {

    let calendar = Calendar.current

    let components = calendar.dateComponents([.day, .hour, .minute, .second], from: Date(timeIntervalSince1970: timeInterval/1000), to: Date())

    guard let days = components.day, let hours = components.hour, let minutes = components.minute else {return ""}

    switch days {
    case 366...:
        return "\(days/365) years ago"
    case 7...:
        return "\(days/7) \(days/7 == 1 ? "week" : "weeks") ago"
    case 1...:
        return "\(days) \(days == 1 ? "day" : "days") ago"
    default:
        if hours > 0 {
            return "\(hours) \(hours == 1 ? "hour" : "hours") ago"
        }else if minutes > 0 {
            return "\(minutes) \(minutes == 1 ? "minute" : "minutes") ago"
        }else{
            return "now"
        }
    }

}

timeSinceNowString(1532194221795) // "3 weeks ago"

谢谢!这对该错误有效。我仍然在这行代码中遇到“表达式类型不明确,没有更多上下文”错误让components=calendar.dateComponents([.day、.hour、.minute、.second],from:self,to:Date())什么实例“self”指的是什么?