检查时间跨度 [英] checking timespan
本文介绍了检查时间跨度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个查询活动目录,并返回最后一个密码重置的值的局部变量的方法。我想比较该值当前日期和时间,并检查它已经不到24小时。我觉得我接近,但似乎无法得到这个工作。
谢谢, 杰森
字符串passwordLastSet =的String.Empty;
passwordLastSet = DateTime.FromFileTime((Int64的)(result.Properties [的pwdLastSet] [0]))的ToString()。
公共字符串lastReset(日期时间pwordLastReset)
{
如果(DateTime.Now.AddHours(24)< = passwordLastSet)
{
返回稍后再试;
}
其他
{
回到一切都很好;
}
}
解决方案
本:
如果(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))
这篇关于检查时间跨度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文