In the user permission system, it is sometimes necessary to determine whether to expire based on the user's contract time and contract duration. First help class:
public static class DateExprieHelper
{ /// <summary>
/// Determine whether to expire Based on the Contract Signing time and contract duration
/// </summary>
/// <Param name = "joindate"> contract time </param>
/// <Param name = "duration"> contract duration </param>
/// <returns></returns>
public static bool IsExpriredByDay(DateTime joinDate, double duration)
{ return DateTime.Now - joinDate > TimeSpan.FromDays(duration);
}
}
Client call.
class Program
{ static void Main(string[] args)
{ var result = DateExprieHelper.IsExpriredByDay(new DateTime(2014, 1, 1), 365);
if (result)
{Console. writeline ("expired ~~ "); }
else
{Console. writeline ("not expired yet ~~ "); }
Console.ReadKey();
}
}
The result shows that the instance has not expired ~~
Determine whether the date expires