create a Timestamp object in angularfire app
Asked Answered
F

4

5

First tried

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

and then how to create a Timestamp object?

var now: Timestamp = ???

var now: Timestamp = Timestamp.now() //Module not found: Error: Can't resolve '@firebase/firestore-types'
Flashy answered 22/7, 2018 at 3:59 Comment(0)
P
5
import { Timestamp } from '@firebase/firestore-types';

Here Timestamp is just a type, if you want to get the current time just use

var now = new Date(;
Peterpeterborough answered 22/7, 2018 at 4:3 Comment(0)
N
2

JS Date objects do get saved as timestamps in Firestore/firebase:

ref.update({ updatedAt: new Date() })
// results in timestamp in Firestore
Nystatin answered 19/11, 2018 at 9:59 Comment(1)
This is the actual answerMichaelmas
A
2

Using serverTimestamp() method to update the Timestamp object

import {serverTimestamp } from 'firebase/firestore';

ref.update({ updatedAt: serverTimestamp() })
// results in timestamp in Firestore
Allegro answered 25/8, 2022 at 13:46 Comment(0)
R
0

Don't use Timestamp from firestore-types. The one you can use is available in firestore.

Use import { Timestamp } from "@firebase/firestore";

instead of import { Timestamp } from "@firebase/firestore-types";

Then you can use: Timestamp.fromDate(new Date());

Rolfrolfe answered 19/7, 2023 at 5:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.