Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get rid of the 00:00:00.000 so that it's just the date in Flutter

I want to change the pickerDate to a string in the format of dd-MM-yyyy, right now its in the format yyyy-dd-MM 00:00:00.000. How can I change this?

String _selectedDate = DateFormat("d-MM-yyyy").format(DateTime.now());

_getDateFormUser() async {
    DateTime? pickerDate = (await showDatePicker(
        context: context,
        initialDate: DateTime.now(),
        firstDate: DateTime(2015),
        lastDate: DateTime(2121)));

    if (pickerDate != null) {
      setState(() {
        _selectedDate = pickerDate.toString();
      });
    } else {
      //empty
    }
  }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You’ve already created the DateFormatter, you just need to use it instead of .toString().

_selectedDate =  DateFormat("d-MM-yyyy").format(pickerDate);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading