How to format DateTime in Flutter

前端 未结 9 1770
悲哀的现实
悲哀的现实 2020-12-04 10:28

I am trying to display the current DateTime in a Text widget after tapping on a button. The following works, but I\'d like to change the format.

9条回答
  •  被撕碎了的回忆
    2020-12-04 11:26

    there is some change since the 0.16 so here how i did,

    import in the pubspec.yaml

    dependencies:
          flutter:
            sdk: flutter
          intl: ^0.16.1
    

    then use

      txdate= DateTime.now()
    
    
      DateFormat.yMMMd().format(txdate)
    

提交回复
热议问题