我需要两个日期时间精确到毫秒第一比较对象日期时间将是小于第二的区别,它停在GridView的循环删除事件日期时间的时间差和毫秒
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
if (!Ok2Delete(e.RowIndex)) return;
// your logic goes here and the above IF statement
// will hopefully guarantee your code to run once.
}
private bool Ok2Delete(int ri) // ri is the record index to be deleted
{
if (Session["ri"] == null ||
(!((ri == ((int)Session["ri"])) &&
(DateTime.Now.Subtract((DateTime)Session["ri_time_stamp"]).Seconds < 2))))
{
Session["ri"] = ri;
Session["ri_time_stamp"] = DateTime.Now;
return true;
}
return false;
}
这个代码不按预期工作
您的代码在OK2Delete函数中寻找的差异超过了2秒。你到底在找什么呢?大于0毫秒? – 2012-01-10 04:13:05
也请使用DateTime.UtcNow而不是DateTime.Now。它使您的应用程序独立于机器和TimeZone。 – 2012-01-10 04:17:56
那么大家都做出了努力,所以我需要选择一个答案,但它并没有工作 – ONYX 2012-01-11 20:39:11