How to print Firestore timestamp as formatted date and time

前端 未结 13 1839
野性不改
野性不改 2021-02-07 11:07

My timestamp returns Timestamp(seconds=1560523991, nanoseconds=286000000) in a Flutter Firestore snapshot.

I want to print it as properly formatted date and

13条回答
  •  天命终不由人
    2021-02-07 11:56

    It took a long time to find the perfect answer. When you fetch the data from Firestore as a Timestamp object and you are sure about that then I will recommend you use the following code:

    DateTime fetchedDate = e.data()["deadline"]?.toDate();
    

    using ?.toDate() worked for me and hopefully will also work for you.

提交回复
热议问题