DateTime now = DateTime.now();
DateTime time = DateTime.parse('2018-12-31');
if (now.isBefore(time)) {
Duration duration = time.difference(now);
print(duration.inDays.toString());
}
Dart中,日期可通过isAfter或者isBefore判断日期的先后,通过difference()方法比较两个日期之间的差值