Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

firebase timestamp to date angular

import { firestore } from 'firebase/app';
import Timestamp = firestore.Timestamp;

@Injectable()
export class YourService {

....

    list = (): Observable<any[]> => this.collection
        .snapshotChanges()
        .pipe(
            map(changes => {
                return changes.map(a => {
                    const data = a.payload.doc.data() as any;
                    Object.keys(data).filter(key => data[key] instanceof Timestamp)
                        .forEach(key => data[key] = data[key].toDate())
                    data._id = a.payload.doc.id;
                    return data;
                });
            })
        );

...
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #firebase #timestamp #date #angular
ADD COMMENT
Topic
Name
1+1 =