HoRiz
HoRiz

Reputation: 787

How to Store DateTime as a timestamp - Firebase flutter

I use this method to send time to firestore, But the type of "time" filed in the collection is int.

Map<String, dynamic> Qnote= {
      "note": note,
      "sender": username,
      "uid": uid,
      "time": DateTime.now().microsecondsSinceEpoch, // <---- here
    };

    FirebaseFirestore.instance.collection("Note").doc(noteId).collection("QuickNote").add(Qnote);

enter image description here

How to save time field as timestamp in collection?

Upvotes: 0

Views: 1115

Answers (1)

JideGuru
JideGuru

Reputation: 7660

What you need is Timestamp.fromDate(DateTime.now())

Map<String, dynamic> Qnote= {
      "note": note,
      "sender": username,
      "uid": uid,
      "time": Timestamp.fromDate(DateTime.now()), // <---- here
    };

Upvotes: 2

Related Questions