swift - Firebase Firestore 时间戳至今问题

标签 swift firebase timestamp google-cloud-firestore

将我的代码升级到 Swift 5 后,Firestore 将 NSDate 返回为 FIRTimestamp。当我尝试将其作为 Date 接收时,它会抛出错误:

Could not cast value of type 'FIRTimestamp' (0x107aab8c0) to 'NSNumber' (0x10b8fbe00).

如何解决这个问题?

最佳答案

以下代码用于从 Firestore 获取时间戳值并将其转换为 NSDate

let timestamp: Timestamp = (filteredtotalArray[indexPath.row] as AnyObject).value(forKey: "requestedDate")! as! Timestamp
let RequestedDate = timestamp.dateValue()

关于swift - Firebase Firestore 时间戳至今问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55757854/

相关文章:

swift - Alamofire JsonEncoding 和 UrlEncoding

swift - 在 swift 中使用 switch 语句的 bool 函数

python - 将另一列的分钟数添加到 pyspark 中的字符串时间列

java - 如何解决时间戳java + firestore问题?

mysql - 为什么mysql时间戳列使用时间戳来搜索得到更大的结果?

arrays - 在通用和惯用的 Swift 中递归计算多维数组中的项目

ios - 如果电子邮件未经验证,Apple将替换电子邮件提供商

ios - Swift Firebase UITableViewCell 在填充单元格的数据可用之前加载

java - 有没有办法将 firestore 中的数据值存储到数组中?

javascript - 将字段存储到 firestore 时尝试在字段名称中传递变量