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.
DateTime
Text
Use this function
todayDate() { var now = new DateTime.now(); var formatter = new DateFormat('dd-MM-yyyy'); String formattedTime = DateFormat('kk:mm:a').format(now); String formattedDate = formatter.format(now); print(formattedTime); print(formattedDate); }
Output:
08:41:AM 21-12-2019