Anh Nguyễn Tuấn
Anh Nguyễn Tuấn

Reputation: 101

create a Timestamp object in angularfire app

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

Answers (4)

Claudio Cafre
Claudio Cafre

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

Alam
Alam

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

Govind Samrow
Govind Samrow

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

Sajeetharan
Sajeetharan

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

Related Questions