Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get firestore timestamp

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

enter image description here

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?

like image 976
Paco Zevallos Avatar asked Apr 25 '18 00:04

Paco Zevallos


People also ask

What is firestore timestamp?

Summary. When this is stored as part of a document in Firestore, it is truncated to the microsecond, towards the start of time. A Timestamp represents a point in time independent of any time zone or calendar, represented as seconds and fractions of seconds at nanosecond resolution in UTC Epoch time.

How do I get Firebase time?

To reach the timestamp of firebase server on client, you first need to write the value to the server then read the value. firebase. database(). ref('currentTime/').

How do I convert firestore timestamp to date?

firestore. Timestamp. fromDate to convert the a date to a Firestore timestamp. We call toDate on the timestamp object to convert it back to a JavaScript date.

Is Firebase firestore real time?

Firebase offers two cloud-based, client-accessible database solutions that support realtime data syncing: Cloud Firestore is Firebase's newest database for mobile app development. It builds on the successes of the Realtime Database with a new, more intuitive data model.


1 Answers

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.

like image 182
Papa Kojo Avatar answered Oct 12 '22 15:10

Papa Kojo