241*_*116 2 kotlin google-cloud-firestore
不知道为什么我找不到我要找的东西。但我只想将当前时间存储到 Firestore 文档中,如下所示:
。在 Flutter 中我们只是这样做:
'timestamp': DateTime.now()
我尝试在 kotlin 中这样做:
"timestamp" to LocalDateTime.now()
但它给了我一些复杂的领域:
所有平台上的最佳方法是使用 SDK 提供的服务器时间戳令牌(而不是使用客户端的时钟,这可能是错误的)。
文档在这里。
// Update the timestamp field with the value from the server
val updates = hashMapOf<String, Any>(
        "timestamp" to FieldValue.serverTimestamp()
)
docRef.update(updates).addOnCompleteListener { }
如果您确实想要客户端时钟的时间,只需传递 java Date withDate()或Timestamp with Timestamp.now()。
| 归档时间: | 
 | 
| 查看次数: | 2504 次 | 
| 最近记录: |