mes*_*eeb 10 javascript firebase google-cloud-firestore
Firebase Firestore最近更改了他们管理时间戳的方式,我无法date从时间戳中检索对象.
如何从新的日期对象中获取日期对象firebase.firestore.FieldValue.serverTimestamp()?
mes*_*eeb 29
你只需要这样做:
yourFirestoreTimestamp.toDate()
Run Code Online (Sandbox Code Playgroud)
如果您Timestamp在控制台中查看对象,您将看到这.toDate()是Timestamp对象中保存的众多信息之一:
Nag*_*aba 10
终于,我可以得到我需要的东西了
new Date(firebase.firestore.Timestamp.now().seconds*1000).toLocaleDateString()
Run Code Online (Sandbox Code Playgroud)
firebase.firestore.FieldValue.serverTimestamp()只返回在将字段写入文档时使用的哨兵对象。它指示服务器应将其替换为实际Timestamp对象。 serverTimestamp()本身不包含任何日期信息,因此您不能将其转换为日期。当您从文档中读回值时,该字段将包含一个Timestamp对象,您可以使用其toDate()方法将其转换为本地Date对象。
| 归档时间: |
|
| 查看次数: |
8759 次 |
| 最近记录: |