I am trying to get the time difference of two time values , one coming from a json object in the format of
DateFormat('dd-MM-yyyy HH:mm:ss')
and the other is from
DateTime.now()
. Since DateTime.now()
is coming in this format "2020-06-23 08:10:36.411419" including the microseconds.
In which case I cannot get the difference of these two time values because value coming from json has no microseconds.
So I have to format the DateTime.now() value to match the json value.(cleaningStartTime is the value coming from json)
So I wrote this code
var formatTime = DateFormat('yyyy-MM-dd HH:mm:ss');
var timeNow = formatTime.format(DateTime.now());
var diff = timeNow.difference(cleaningStartTime);
But when i try to return the "diff" value it gives me this error.
The method 'difference' isn't defined for the class 'String'. Try correcting the name to the name of an existing method, or defining a method named 'difference'. var diff = timeNow.difference(cleaningStartTime);
How do I approach to fix this issue ?
flutter version = v1.17.1