Hi there in my code i have to return if the date is older than 24 hours than it should return me the date and if not it should return me the difference in hours.
publishtime: DateTime.now().subtract(Duration(days: 10));
_getTime() {
String time;
DateTime now = DateTime.now();
Duration difference = publishtime.difference(now);
if (difference.inHours > 24) {
var format = DateFormat("dd.MM.yyyy");
time = format.format(publishtime);
} else {
time = difference.inHours.toString().replaceAll('-', '') + " hours ago";
}
return time;
}
it returns me "240 hours ago" but it should return me the date
why dont the if (difference.inHours > 24) work as it should? the difference.inHours also return a int value so why dont it work?