我需要兩個日期時間精確到毫秒第一比較對象日期時間將是小於第二的區別,它停在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