如何在 Angular 中将数据保存为 Firestore Timestamp 对象 [英] How to save data as Firestore Timestamp object in Angular

查看:28
本文介绍了如何在 Angular 中将数据保存为 Firestore Timestamp 对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想在 Firestore 数据库中将日期保存为时间戳,但它将时间戳存储为数字:

Just want to save Date as timestamp in Firestore database but it's storing timestamp as number:

save() {
    const data = this.transactionForm.value;
    data.type = data.type == 'true' || data.type == true ? true : false;
    data.updated = firebase.firestore.FieldValue.serverTimestamp();
    // Date string to timestamp
    data.date =  new Date(data.date.split("-").reverse().join("-")).getTime();
    let id = data.id;
    this.transCollection.doc(id).update(data);
}  

推荐答案

我在 Firebase 中使用时间戳,我知道它用于将日期存储在 long 中,即数字.所以不知道Firestore是不是一样.

I use timestamp in Firebase and I know it is use to store date in long which is number. So I dont know if it is the same in Firestore.

这篇关于如何在 Angular 中将数据保存为 Firestore Timestamp 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆