datetimeflutterdart

How to convert string to DateTime object with month name, Date and Year flutter?


I have string like "April 20, 2020". I want to convert the string to DateTime().

The problem I am facing is DateTime.parse() is not accepting month name.


Solution

  • Those type of date format is not supported by DateTime parse. You can use intl package to achieve this.

    var dateString    = 'April 20, 2020';
    DateFormat format = new DateFormat("MMMM dd, yyyy");
    var formattedDate = format.parse(dateString);