如何获取firestore时间戳 [英] How to get firestore timestamp

查看:32
本文介绍了如何获取firestore时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取我在 firestore 中创建的文档的时间戳,但我得到的是:

I'm trying to get the timestamp of a document that I created in firestore, but what I get is this:

myService.ts

getDomiciliarios() {
this.domiciliarios = this.afs.collection('domiciliarios').snapshotChanges().map(actions => {
  return actions.map(a => {
    const data = a.payload.doc.data() as Domiciliario;
    const id = a.payload.doc.id;
    const date = firebase.firestore.FieldValue.serverTimestamp();
    return { id, ...data, date };
  });
});

return this.domiciliarios;
}

myComponent.ts

ngOnInit() {
const domiciliarios = this.fs.getDomiciliarios()
  .subscribe(data => this.dataSource.data = data, date => date);
}

myComponent.html

<ng-container matColumnDef="fecha">
  <mat-header-cell *matHeaderCellDef mat-sort-header> Fecha </mat-header-cell>
  <mat-cell *matCellDef="let domiciliario"> {{ domiciliario.date }} </mat-cell>
</ng-container>

我应该如何打印该时间戳,之前是否应该创建它?

How can I print that timestamp, should I have previously created it?

推荐答案

如果你想要 firebase.firestore.FieldValue.serverTimestamp() 的日期值,你可以使用 .toDate().请参阅 FireStore 时间戳.在您的情况下,它将是您模板中的 domiciliario.date.toDate().

IF you want the date value of firebase.firestore.FieldValue.serverTimestamp() you can use .toDate(). See FireStore Timesteamp. In your case it will be domiciliario.date.toDate() in your template.

这篇关于如何获取firestore时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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