1

I am trying to parse data and time from an API about a certain Schedule, the response I'm getting is of the form " 2019-10-09T13:00:00.000Z " and " 2019-10-09T14:30:00.000Z ".

How to obtain the date and time from this in Dart?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
  • Possible duplicate of [convert datetime string to datetime object in dart?](https://stackoverflow.com/questions/49385303/convert-datetime-string-to-datetime-object-in-dart) – jamesdlin Sep 23 '19 at 06:07

3 Answers3

1

Use DateTime.tryParse(). It will return null if the input can’t be parsed to a datetime object. But the format you receive should be fine.

Jalil Compaoré
  • 394
  • 3
  • 12
0

You can convert your date and time like substring

  DateTime follow = DateTime.parse("${f.followDate.substring(6,10)}-${f.followDate.substring(3,5)}-${f.followDate.substring(0,2)}");
Hardik Kumbhani
  • 2,013
  • 10
  • 18
0

First convert to DateTime object, it will automatically parse time

Datetime d1= DateTime.parse(strDate);

then connvert to time required by you

 String date = DateFormat('dd-MMM-yyyy HH:mm').format(d1);
theshivamlko
  • 271
  • 2
  • 10