1

I am trying to display a DateTime as text in a ListTile.

What I have done gives me the message:

The argument type 'String' can't be assigned to the parameter type 'DateTime'

Code:

_getDate() {
    String formattedDate = DateFormat(yyyy-MM-dd).format(widget.exampleForDate.myDate);
    return ListTile(
      title: Text(formattedDate),
    );
  }
CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440

2 Answers2

0

Use intl package to access DateFormat

DateTime dateTime = widget.exampleForDate.myDate; // your dateTime object
DateFormat dateFormat = DateFormat("yyyy-MM-dd"); // how you want it to be formatted
String string = dateFormat.format(dateTime); // format it 

Use it like

ListTile(title: Text(string));
CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
0

Simple in Java Script Date().toString()

Amit kumar
  • 457
  • 6
  • 14