Home > Blockchain >  Error while trying to convert the String format dateTime into DateTime format in flutter
Error while trying to convert the String format dateTime into DateTime format in flutter

Time:09-06

I am trying to convert the date time in the string format to DateTime but its showing "FormatException (FormatException: Trying to read dd from MONDAY at position 0)"

safePrint(Intl.withLocale(
              'en',
              () => new DateFormat("dd, EEE MMM yyyy HH:mm:ss \'GMT\'")
                  .parse(batch_timing[j])));

          print(new DateFormat('dd, EEE MMM yyyy HH:mm:ss \'GMT\'')
              .parse(batch_timing[j]));

Note : date format is "Mon, 05 Sep 2022 10:00:00 GMT"

CodePudding user response:

There is a correction in converting :

check the below

 String mDate ="Mon, 05 Sep 2022 10:00:00 GMT";

    print(DateFormat('EEE, dd MMM yyyy HH:mm:ss \'GMT\'')
              .parse(mDate));

you have to use EEE, dd MMM yyyy HH:mm:ss \'GMT\'' instead of dd, EEE MMM yyyy HH:mm:ss \'GMT\''

  • Related