android - Firebase firestore:如何在 Android 的 Kotlin 中以秒为单位创建时间戳
问题描述
我正在尝试通过将秒数传递给它来创建一个 Firebase Firestore 时间戳对象,但它不起作用。
这是代码片段。
import com.google.firebase.Timestamp
import com.google.firebase.firestore.*
var timeStampString:String = "1438910477"
var t = timeStampString.toLong()
var ts = Timestamp(t)
我收到错误:
None of the following functions can be called with the arguments supplied
<Init>(Parcel) defined in com.google.firebase.Timestamp
<Init>(Date) defined in com.google.firebase.Timestamp
如文档中所述,我将数字作为参数传递。但它期待“包裹”或“日期”。
我究竟做错了什么?
解决方案
正如您从链接到的 API 文档中看到的那样,构造函数需要两个数字参数,而不是一个。如果您在纳秒内没有要传递的组件,则传递 0:
var timeStampString:String = "1438910477"
var t = timeStampString.toLong()
var ts = Timestamp(t, 0)
但是,当您可以直接编码数字时,为什么要将字符串解析为数字:
var t = 1438910477
var ts = Timestamp(t, 0)
推荐阅读
- python - 选择具有 id pyspark 列表的多行
- c++ - 修复视频FPS opencv?
- mysql - 尽管有索引,但 MySQL 的选择查询性能很差
- go - “go build -buildmode=c-shared”编译的dll,如何隐藏导出的goruntime函数?
- swift - 在 alamofire manger 类 swift 中添加公钥固定
- c# - 如何在 CSV 文件中随机生成一个单词
- vuejs2 - 当滚动条在VueJs中到达底部时如何执行功能
- node.js - 使用从另一个模块(node.js)导入的函数
- apache-spark - pyspark 加入两个数据框并按最近日期保留行
- elasticsearch - 我们可以将 char_filter 应用于 elasticsearch 中的自定义标记器吗?