Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70432

Convert firestore timestamp to date

$
0
0

@ryan-kelly1997 wrote:

I have an app with a calendar, I want to add events to this calendar by fetching data from firebase on events and passing the dates through.

I have made a sample collection called ‘competition’ with a date in timestamp format.

When i console.log(), I can see the timestamp field which is called datecomp is being passed through in Epoch seconds as below
datecomp: t {seconds: 1585396800, nanoseconds: 0}

How can I convert this in Angular to get in the format of a date which can be loaded into the calendar? I know I need to use the toDate() function but how exactly would I write it?

The basic code I have so far is here for reference

Any help would be appreciated

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);
})
}

HTML

<ion-calendar [(ngModel)]="date"
  (onChange)="onChange($event)"
  [type]="type"
  [format]="'YYYY-MM-DD'">
</ion-calendar>

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70432

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>