I am getting timestamp from firestore. How to show it in Date/month/year in flutter? Tried so many ways but it shows error: String is subtype of Timestamp or datetime. Below is my code.
itemCount: orderList.data.docs.length,
itemBuilder: (ctx, index) {
final cartOrder = orderList.data.docs[index]['cartorder'];
final Timestamp orderedDate =
orderList.data.docs[index]['ordered_date'];
final delivered = orderList.data.docs[index]['delivered'];
String myDate =
DateFormat('dd/MM/yyyy,hh:mm').format(orderedDate.toDate());
Thanks a lot.
CodePudding user response:
You are getting a timestamp. Use DateTime.fromMillisecondsSinceEpoch
DateTime date = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000);
String myDate = DateFormat('dd/MM/yyyy,hh:mm').format(date);