1

_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

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56
Abdullah
  • 35
  • 1
  • 9
  • What kind of server? It's possible you'll want to avoid any string phase and do it as number-to-number transfers. True of things like Firebase and others. – Randal Schwartz Aug 20 '22 at 00:47
  • Why convert the `DateTime` to a `String` just to convert it back to a `DateTime` later? You should convert the `DateTime` to a `String` *only* when you need to display it. You should be storing the `DateTime`, not its `String` representation. – jamesdlin Aug 20 '22 at 03:28

1 Answers1

2

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.

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56