Firebase date type field conversion

I am receiving data from firestore in the below format of the field whose type is Date.

{
    "seconds": 1642512053,
    "nanoseconds": 303000000
}

Above value is saved in firestore as

January 18, 2022 at 6:58:19 PM UTC+5:30

I want to display the value in dd/mm/yyyy hh:mm AMPM; however toDate, DatePipe, formatDate... none method works. I did string conversion and then converted it to date from seconds which is too much tedious.

Has anyone faced a similar problem and any short-cut trick?


Those pipes take milliseconds. You could do something like this:

class:

  data = {
    "seconds": 1642512053,
    "nanoseconds": 303000000
  };

html:

{{ data.seconds * 1000 + data.nanoseconds / 1000000 | date: 'dd/mm/yyyy hh:mm a' }}

Which at the time of writing this outputs: 18/20/2022 08:20 AM.

Here's a stackblitz showcasing it:

https://stackblitz.com/edit/angular-c2u4ms?file=src%2Fapp%2Fapp.component.html