Comparing only dates of DateTimes in Dart

后端 未结 4 1461
予麋鹿
予麋鹿 2020-12-29 23:56

I need to store and compare dates (without times) in my app, without caring about time zones.
I can see three solutions to this:

  1. (date1.year == da

4条回答
  •  执念已碎
    2020-12-30 00:10

    Use instead the package: dart_date Dart Extensions for DartTime

    dart_date provides the most comprehensive, yet simple and consistent toolset for manipulating Dart dates.

    dart_date

    DateTime now = DateTime.now();
    DateTime date = ....;
    if (date.isSameDay(now)) {
      //....
    } else {
      //....
    }
    

    Also here the difference in days :

    int differenceInDays(DateTime a, DateTime b) => a.differenceInDays(b);
    

提交回复
热议问题