Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert the firebase timestamp using angular date pipe

I am trying to display some firebase timestamp in the template view, Unfortunately no luck with the angular datePipe.

<p>Seen {{user.updatedAt | date: 'yyyy/MM/dd h:mm:ss a'}}</p> 

I do get this error:

     ERROR Error: InvalidPipeArgument:  'Unable to convert "Timestamp(seconds=1528515928, nanoseconds=105000000)"  into a date' for pipe 'DatePipe 
like image 614
LearnToday Avatar asked Jun 09 '18 03:06

LearnToday


People also ask

How do I change firestore timestamp to date?

To convert a Firestore date or timestamp to a JavaScript Date, we use firebase. firestore. Timestamp. fromDate to convert the a date to a Firestore timestamp.

How do I display firebase timestamp?

The proper way to attach a timestamp to a database update is to attach a placeholder value in your request. In the example below Firebase will replace the createdAt property with a timestamp: firebaseRef = firebase. database().

What format is firestore timestamp?

firestore. Timestamp. 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. It is encoded using the Proleptic Gregorian Calendar which extends the Gregorian calendar backwards to year one.


Video Answer


1 Answers

You can either convert Timestamp to milliseconds or to Date:

<p>Seen {{user.updatedAt.toMillis() | date:'yyyy/MM/dd h:mm:ss a'}}</p> 

or

<p>Seen {{user.updatedAt.toDate() | date:'yyyy/MM/dd h:mm:ss a'}}</p> 
like image 162
dRamentol Avatar answered Oct 04 '22 10:10

dRamentol