更新时间:2023-02-26 16:37:49
本:
如果(DateTime.Now.AddHours(24)< = passwordLastSet)
应
如果(DateTime.Now< = passwordLastSet.AddHours(24))
I have a method that queries active directory, and returns the value of the Last Password Reset to a local variable. I am trying to compare that value to the current date and time, and check if it's been less than 24 hours. I think I'm close, but can't seem to get this to work.
Thanks, Jason
string passwordLastSet = string.Empty;
passwordLastSet = DateTime.FromFileTime((Int64)(result.Properties["PwdLastSet"][0])).ToString();
public string lastReset(DateTime pwordLastReset)
{
if (DateTime.Now.AddHours(24) <= passwordLastSet)
{
return "try again later";
}
else
{
return "all is good";
}
}
This:
if (DateTime.Now.AddHours(24) <= passwordLastSet)
should be
if (DateTime.Now <= passwordLastSet.AddHours(24))