Reputation: 11
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?
Upvotes: 1
Views: 227
Reputation: 281
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);
Upvotes: 0
Reputation: 2021
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)}");
Upvotes: 0
Reputation: 404
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.
Upvotes: 1