Reputation: 101
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'
Upvotes: 5
Views: 5605
Reputation: 11
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());
Upvotes: 0
Reputation: 321
Using serverTimestamp() method to update the Timestamp object
import {serverTimestamp } from 'firebase/firestore';
ref.update({ updatedAt: serverTimestamp() })
// results in timestamp in Firestore
Upvotes: 2
Reputation: 10187
JS Date objects do get saved as timestamps in Firestore/firebase:
ref.update({ updatedAt: new Date() })
// results in timestamp in Firestore
Upvotes: 2
Reputation: 222720
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(;
Upvotes: 5