Sampath
Sampath

Reputation: 65870

Firestore timestamp with ngx-moment is not working

I use ngx-moment library. I need to format a datetime like so Mar 12 at 11 PM

I have tried like so:

.html

<p>{{invitedEvent.startDatetime | amDateFormat: 'MMM DD'}} at {{invitedEvent.startDatetime | amDateFormat: 'hh A'}}</p>

But it gives this error:

Invalid date at Invalid date

Here I use Firestore timestamp DateTime like so:

enter image description here

Above library is working fine if I use like so <p>{{'24/01/2014' | amParse:'DD/MM/YYYY' | amDateFormat: 'MMM DD'}}</p>

But what value should I pass here amParse?

Upvotes: 1

Views: 1229

Answers (2)

Alexander D&#237;az
Alexander D&#237;az

Reputation: 1

Moment works with timestamp and format ISO 8601, change your timestamp format in Firestore.

Upvotes: 0

Sampath
Sampath

Reputation: 65870

This works for me.

 <p>{{invitedEvent.startDatetime.toDate() | amDateFormat: 'MMM DD'}} at
          {{invitedEvent.startDatetime.toDate() | amDateFormat: 'h:mm A'}}</p>

Note: I have used .toDate() and Changed startDatetime:string to startDatetime: Timestamp;

i.e. import { Timestamp } from '@firebase/firestore-types';

Upvotes: 2

Related Questions