本文介绍了使用C#比较ASP.NET中的小时数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有人,
我正在尝试比较两个约会时间,如下所示:
Dear All,
I am trying to compare two date hours as below:
DateTime Login =Convert.ToDateTime(ds.Tables[1].Rows[0]["Login"]);
DateTime Logout = Convert.ToDateTime(ds.Tables[1].Rows[0]["LogOut"]);
int var = DateTime.Compare(Login,Logout);
if (var > 3 )
{
lblCount.Text = "0";
}
在这里,我实际上是在检查登录和注销之间的差异是否超过3小时,然后:
Here, I am actually checking if the difference between login and Logout is more than 3 hours then :
lblCount.Text = "0";
我认为这是不正确的.有人可以建议我如何比较3小时的日期吗?
I don''t think its correct. Can any one please suggest me how to compare the dates for 3 hours?
推荐答案
string INDate = "2011-02-02 4:45:25";
string OutDate = "2011-02-02 12:33:33";
DateTime startDate = Convert.ToDateTime(INDate);
DateTime endDate = Convert.ToDateTime(OutDate);
TimeSpan diff = endDate.Subtract(startDate);
string FV = diff.TotalHours.ToString();
祝你好运.....
Best of Luck.....
这篇关于使用C#比较ASP.NET中的小时数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!