How can I tell if DateTime.Now() is on a day AFTER a different DateTime

后端 未结 5 1499
庸人自扰
庸人自扰 2021-01-23 17:43

I\'m running this on flutter, but I guess this could be a more general issue.

I am saving a DateTime in the preferences. I want to be able to then tell if DateTime

5条回答
  •  执念已碎
    2021-01-23 18:17

    Figured out another potential solution!

    In addition to checking if the day is different (which by itself won't work) you can also check the month and year. Only 1 of those needs to differ for it be true :)

    if (now.isAfter(lastDailyCheck)) {
      if (now.day != lastDailyCheck.day ||
          now.month != lastDailyCheck.month ||
          now.year != lastDailyCheck.year) {
        return true;
      }
    }
    

提交回复
热议问题