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

576 Views Asked by At

_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

1

There are 1 best solutions below

1
Md. Yeasin Sheikh On BEST ANSWER

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.