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


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.

Answered By – Yeasin Sheikh

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published