datetimeflutterdarttostringformatted

In Flutter i got a DateTime [yyyy-MM-dd 00:00:00.000] how can i transfer that to be [yyyy-MM-dd] only?


here is the code which i already formatted it to be [yyyy-MM-dd] but it also contains 00:00:00 :


    child: Text(
         _selectedDate == null
     ? 'No Date Choosen!'
     : '${DateFormat('yyyy-MM-dd').format(_selectedDate)}',
     style: TextStyle(
     color: Colors.white, fontSize: 16),),


Solution

  • You need to create a new DateFormat object.

    final df = new DateFormat('yyyy-MM-dd');
    Text(_selectedDate == null ? 'No Date Choosen!' : '${df.format(_selectedDate)}');