ios - 从 Swift 中的 firebase 获取时间戳
问题描述
我想从 firebase 获取我的时间戳并将其转换为我们的正常时间 hh:mm: a 并且我已经完成了:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: PrivateMsgMainMenuTableViewCell = self.tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! PrivateMsgMainMenuTableViewCell
let ref = Database.database().reference().child("privateMessages")
ref.observeSingleEvent(of: .childAdded) { (snapshot) in
for rest in snapshot.children.allObjects as! [DataSnapshot] {
let messageID = rest.key
let ref2 = Database.database().reference().child("privateMessages").child(messageID).queryLimited(toLast: 1)
ref2.observeSingleEvent(of: DataEventType.value) { (snap) in
let messageDetails = snap.children
while let timeSent = messageDetails.nextObject() as? DataSnapshot {
let timeSentDetails = (timeSent.value as! [String: AnyObject])["timestamp"] as? Double
let converted = NSDate(timeIntervalSince1970: timeSentDetails! / 1000)
let dateFormatter = DateFormatter()
dateFormatter.timeZone = NSTimeZone.local
dateFormatter.dateFormat = "hh:mm a"
let time = dateFormatter.string(from: converted as Date)
DispatchQueue.main.async {
cell.timeLabel.text = time
}
}
}
}
}
return cell
}
我正在尝试检索最后发送消息的时间并显示在我的表格视图中的标签中,但我不确定为什么它不显示以及之后的代码
let timeSentDetails = (timeSent.value as! [String: AnyObject])["timestamp"] as? Double
当我设置断点时不运行。我在这里犯了什么错误吗?
解决方案
推荐阅读
- php - 如何在表格中制作按钮以路由到 url
- r - 学习base R的好资源
- qaf - 在 Qmetry 中执行 POST 请求时出错
- validation - Blazor WASM 中的可重用验证
- django - 无法更改隐藏字段中的值
- c# - C# 中的 SAP Web 服务问题
- webdriver - java.lang.AssertionError:地图与键不匹配:国家实际:Mgdtoemizqbpfrt 预期:
- java - 如何创建一个子类的对象,该对象扩展另一个类,该类位于另一个类中?
- html - 将两个 div(javascript 广告)并排放置
- php - 如何在 PHP 中从另一个页面插入数据