How to print Firestore timestamp as formatted date and time

前端 未结 13 1825
野性不改
野性不改 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:55

    You will get a unix timestamp from firestore even if you send a DateTime to firestore.

    You can parse a DateTime from Firestore with DateTime.fromMillisecondsSinceEpoch(timestamp * 1000);

    The DateTime class has two option to return a sting. toIso8601String() or toString() choose the one you need. Or use eg. DateTime.now().hour; to get the our and create your own output.

    For more information: Check https://api.dartlang.org/stable/2.4.0/dart-core/DateTime-class.html

提交回复
热议问题