日期:2014-05-18 浏览次数:20796 次
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { HiddenField1.Value = DateTime.Now.Ticks.ToString(); } } protected void Button1_Click(object sender, EventArgs e) { DateTime login_time = new DateTime(Convert.ToInt64(HiddenField1.Value)); DateTime submit_time = DateTime.Now; TimeSpan ts = submit_time - login_time; Response.Write("时间间隔(秒):" + ts.Seconds.ToString()); } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <asp:HiddenField ID="HiddenField1" runat="server" /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> </form> </body> </html>