作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 Firebase 调用似乎返回了一个负值。我像这样存储日期值:
["ctn": ServerValue.timestamp()]
当我检查数据库时,它有:
"users" {
"$uid" {
"ctn" : "1505930238317"
}
}
当我尝试将其从数据库中取出并像这样打印时:
dbRootRef.child("users").child(user.getUserUID()).child("ctn").observeSingleEvent(of: .value, with: { (snapshot) in
if let item = snapshot.value as? Int{
timeNow = item
print("db time \(item)")
}
}
控制台显示:
db time -1603282711
有什么想法吗?
最佳答案
时间戳是非常大的数字,在大多数类型化语言中,它们不符合整数数据类型的限制。
您得到一个负值,因为在将时间戳转换为整数时,您已将其设为 overflow .
使用Double
或UInt64
数据类型而不是Int
,您应该会看到正确的值。
if let item = snapshot.value as? UInt64 {
timeNow = item // ensure that timeNow is declared as a UInt64
print("db time \(item)")
}
关于Swift Firebase ServerTime.timestamp() 返回负日期。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46328883/
我的 Firebase 调用似乎返回了一个负值。我像这样存储日期值: ["ctn": ServerValue.timestamp()] 当我检查数据库时,它有: "users" { "$u
我正在尝试从 Firebase 或 Firestore 获取服务器时间。我试过ServerValue.TIMESTAMP但是当我尝试在 Log.d("Time", "${SERVERValue.TIM
我是一名优秀的程序员,十分优秀!