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'

4 Answers 4

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(;
Sign up to request clarification or add additional context in comments.

Comments

2

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

ref.update({ updatedAt: new Date() })
// results in timestamp in Firestore

1 Comment

This is the actual answer
2

Using serverTimestamp() method to update the Timestamp object

import {serverTimestamp } from 'firebase/firestore';

ref.update({ updatedAt: serverTimestamp() })
// results in timestamp in Firestore

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.