Cannot get seconds from Timestamp object from Firestore

Discussão em 'Angular' iniciado por stevenWalters, Janeiro 3, 2025.

  1. I am creating a Todo app in Angular using Firestore as my backend. I am really new to Firebase and I am having trouble storing and fetching dates.

    When I get the dates from firebase and console.log them i get something like this: date: _Timestamp { seconds: 1736290800, nanoseconds: 0 }

    I understand that to get a human readable date out of this i need to access the seconds part of this and convert it. I have tried to use date.seconds and date.getSeconds() but .seconds gives me this error:


    [ERROR] TS2339: Property 'seconds' does not exist on type 'Date'. [plugin angular-compiler]
    ​

    src/app/pages/todolist/todolist.component.ts:79:47:
    79 │ console.log("date: ",todo.deadlineDate.seconds);


    And date.getSeconds() is not recognized as a function.

    It seems like the date retrieved from firebase is not recognized as a Timestamp object.

    I have tried making a Timestamp object of the variable using Timestamp.fromDate() but it did not work.

    I am using Angular 18 with AngularFirestore and the dates are from user input with MatDatePickerModule and MatNativeDateModule and is stored as a Date in the object sent to firebase.

    Appreciate if someone would have a solution to this.

    Continue reading...

Compartilhe esta Página