Flutter 日期转换

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()方法比较两个日期之间的差值

    原文作者:developer_zhao
    原文地址: https://blog.csdn.net/developer_zhao/article/details/85342305
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞