@ryan-kelly1997 wrote:
Hi,
I am a newbie to JS and I want to access a field in firestore collection called datecomp which is a timestamp and pass this date into a calendar so that when the calendar loads on runtime, the date held in the timestamp in the firestore collection is loaded into the calendar.A connection is established with the firestore collection and the value of the timestamp field is being passed through but in Epoch Seconds such as below:
datecomp: t {seconds: 1585396800, nanoseconds: 0}I know I need to convert this into JSdate using toDate() but not sure how to do this and then be able to display it in the calendar.
If anyone could possibly be of help it would be greatly appreciated, I will leave the basic code so far I have below.
Html
Calendar Page <ion-calendar [(ngModel)]="date" (onChange)="onChange($event)" [type]="type" [format]="'YYYY-MM-DD'"> </ion-calendar>
TypeScript:
import { Component } from ‘@angular/core’; import {tap} from ‘rxjs/operators’; import {AngularFirestoreModule, AngularFirestore} from ‘@angular/fire/firestore’; import {Injectable} from ‘@angular/core’; @Component({ selector: ‘app-home’, templateUrl: ‘home.page.html’, styleUrls: [‘home.page.scss’], }) export class HomePage { date: string; type: ‘string’; constructor(private afs:AngularFirestore) { this.afs.collection(‘competition’).valueChanges().subscribe(data=>{console.log(data); }) }
Posts: 1
Participants: 1