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

后端 未结 5 1493
庸人自扰
庸人自扰 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:04

    You can use the difference method to get the difference between 2 dates and check whether those differs in hours with at-least 24 hours. So your if condition becomes:

    if (now.isAfter(lastDailyCheck) &&
        (lastDailyCheck.day != now.day ||
        now.difference(lastDailyCheck).inHours > 24)) {
        print('After');
    }
    

提交回复
热议问题