How to check if a date has passed in C#?

前端 未结 6 1407
执笔经年
执笔经年 2021-01-05 03:24

I\'m reading the date expires cookie (2 hours) from database, and I need to check if this date has passed. What\'s the best way to do this?

For example:

<         


        
6条回答
  •  旧时难觅i
    2021-01-05 03:58

    bool HasPassed2hoursFrom(DateTime now, DateTime expires)
    {
        return (now - expires).TotalHours >= 2;
    }
    

提交回复
热议问题