4

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 Answers4

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(;
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
2

Using serverTimestamp() method to update the Timestamp object

import {serverTimestamp } from 'firebase/firestore';

ref.update({ updatedAt: serverTimestamp() })
// results in timestamp in Firestore
Alam
  • 303
  • 1
  • 3
  • 14
1

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

ref.update({ updatedAt: new Date() })
// results in timestamp in Firestore
Govind Samrow
  • 9,981
  • 13
  • 53
  • 90
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());

SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34