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

前端 未结 6 1377
执笔经年
执笔经年 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条回答
  •  孤城傲影
    2021-01-05 04:06

    public bool HasPassed2hoursFrom(DateTime fromDate, DateTime expireDate) 
    {
        return expireDate - fromDate > TimeSpan.FromHours(2);
    }
    

提交回复
热议问题