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