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 Convert "EEE, MMM d, yyyy hh:mm aaa" DateTime Format to "yyyy-MM-dd HH:mm:ss" DateTime Format in Dart/Flutter?

I am working in a Flutter Project using Dart where I have a String DateTime as Fri, Sep 30, 2022 01:10 PM that I want to convert in DateTime object with 2022-09-30 13:10:00 format.

For this, I tried the below snippet…

String inputDateTime = "Fri, Sep 30, 2022 01:10 PM";
DateFormat formatter = DateFormat('YYYY-MM-DD hh:mm:ss');
String formatted_inputDateTime = formatter.format(inputDateTime);
DateTime inputDateTime_DT = DateTime.parse(formatted_inputDateTime);

But getting error and now getting my required DateTime object.

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

How to fix this up to get required format of DateTime Object?

Note: Before downvoting, leave your reason professionally…

>Solution :

By using intl package, try this:

DateTime tempDate = new DateFormat("EEE, MMM d, yyyy hh:mm aaa")
        .parse('Fri, Sep 30, 2022 01:10 PM');
String formattedDate = DateFormat('yyyy-MM-dd HH:mm:ss').format(tempDate);
print('formattedDate = $formattedDate'); //2022-09-30 13:10:00
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