Comparing only dates of DateTimes in Dart

后端 未结 4 1462
予麋鹿
予麋鹿 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:11

    You can use compareTo:

      var temp = DateTime.now().toUtc();
      var d1 = DateTime.utc(temp.year,temp.month,temp.day);
      var d2 = DateTime.utc(2018,10,25);     //you can add today's date here
      if(d2.compareTo(d1)==0){
        print('true');
      }else{
        print('false');
      }
    

提交回复
热议问题