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

flutter, dart : How convert formatted DateTime to its original form

_date = DateFormat(‘dd-MMM-yyyy’).format(_rawDateTime);

I have formatted the above _date with Intl package for displaying and now I have to send back to server and server require original format so how I can convert the above formatted date back into its original format.
the server required format is 2022-08-19T09:12:15.406Z

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

>Solution :

You track DateFormat and use .parse on string.

final formatter = DateFormat('dd-MMM-yyyy');
final _date = formatter.format(_rawDateTime);
final data = formatter.parse(_date);

For utc

final data = formatter.parse(_date).toUtc(); //2022-08-19 18:00:00.000Z

Only date will be available from this because the formatter already parsed only date part here.

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