How to format DateTime in Flutter

前端 未结 9 1769
悲哀的现实
悲哀的现实 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:25

    Here's my simple solution. That does not require any dependency.

    However, the date will be in string format. If you want the time then change the substring values

    print(new DateTime.now()
                .toString()
                .substring(0,10)
         );   // 2020-06-10
    

提交回复
热议问题