日期:2014-05-18 浏览次数:20479 次
public string dateDiff(DateTime DateTime1, DateTime DateTime2) { string dateDiff = ""; try { TimeSpan ts1 = new TimeSpan(DateTime1.Ticks); TimeSpan ts2 = new TimeSpan(DateTime2.Ticks); TimeSpan ts = ts1.Subtract(ts2).Duration(); dateDiff = ts.Days.ToString() + "Days" + ts.Hours.ToString() + ":" + ts.Minutes.ToString() + ":" + ts.Seconds.ToString() + "." + ts.Milliseconds.ToString() ; } catch { } return dateDiff; }
------解决方案--------------------
函数开始及结束都记录个时间。。
------解决方案--------------------
在Global.asax页面写:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
//记录页面开始加载时间
dt = DateTime.Now;
}
protected void Application_EndRequest(Object sender, EventArgs e)
{
DateTime dt2 = DateTime.Now;//页面加载结束时间
TimeSpan ts = dt2 - dt;//获得页面加载花费时间
HQSoft.HQBLL.TB_Log LogBLL = new HQBLL.TB_Log();
HQSoft.HQModel.TB_Log LogModel = new HQModel.TB_Log();
LogModel.LogDate = DateTime.Now.ToLocalTime();
LogModel.LogType = 1;
LogModel.LogSystem = System.Web.HttpContext.Current.Request.Url.ToString();
LogModel.LogText = "页面加载花费时间:" + ts.TotalMilliseconds.ToString() +"毫秒";
LogBLL.Add(LogModel);
//Response.Write("the request takes:" + ts.TotalMilliseconds.ToString() + " milliseconds");
//Response.Write(System.Web.HttpContext.Current.Request.Url.ToString());
}
------解决方案--------------------