Home > OS >  How to Store DateTime as a timestamp - Firebase flutter
How to Store DateTime as a timestamp - Firebase flutter

Time:12-17

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?

CodePudding user response:

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

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

  • Related