Linh Đặng Tuấn
Linh Đặng Tuấn

Reputation: 31

How to convert DateTime to Timestamp before saving in Firestore in Flutter?

I picked a "date" form datePicker and wanted to save that date (type as DateTime) to Firestore in Timestamp type. I used Firestore.fromDate(date) but it stores data in Firestore as a map(nanoseconds, seconds).

Upvotes: 0

Views: 1106

Answers (1)

Michel Feinstein
Michel Feinstein

Reputation: 14276

Use the Firebase Timestamp class as:

Timestamp.fromMicrosecondsSinceEpoch(myDateTime.microsecondsSinceEpoch)

There are many other constructors, take a look at the docs.

Upvotes: 1

Related Questions