Currently, I am looking to use the current time as an input in Firebase Firestore (timestamp). Initially, when using the code snippet below:
today: number = Date.now();
everything appeared to function correctly. However, the time was only updated once, specifically when the page was downloaded. To address this, I implemented a time update function:
updatedTime(): void {
setInterval(() => {
this.today = new Date();
}, 1000);}
and then triggered it within the ngOnInit()
function:
ngOnInit() {
this.updatedTime();
}
This approach successfully displayed the updated time in the browser. Unfortunately, it did not reflect when attempting to input _today
into Firebase Firestore.
How can this issue be resolved?
Additionally, is it more advisable to utilize the Date object or opt for the timestamp provided by Firebase APIs?