firestore.Timestamp.now();
我试过这种方式,它将日期保存为 map 。
nanoseconds: 388000000
seconds: 1570897877
纳秒和秒类型是数字。
我想使用 angular 将日期保存为 firestore 时间戳。我发现重复的问题没有被接受的答案。
最佳答案
如果要将当前时间添加为 Firestore 文档中的时间戳值,可以使用 FieldValue.serverTimestamp()
添加它。正如 Doug 所提到的,如下例所示:
import * as firebase from 'firebase';
[ . . . ]
db.collection('times').add({time: firebase.firestore.FieldValue.serverTimestamp()});
如果您想获取特定时间,您可以创建一个新的 Date 对象并使用函数
toDateString()
将其添加到您的 Firestore 中。关于它,如下:import * as firebase from 'firebase';
[ . . . ]
date = new Date('2018-11-16T09:48:51.137Z'); //sample date
this.db.collection('times').add({spec_time: this.date.toDateString()});
关于angular - 如何在 Angular Firestore 中将日期保存为时间戳?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58356396/