using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default: System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
{
string connStr = "Server = .; Database = Test; uid = sa";
SqlConnection conn = new SqlConnection (connStr);
SqlCommand comm = new SqlCommand ("select NowDt from Table1 where DtId = 1", conn);
System.DateTime aa; // Time stored in the database
System.DateTime bb; // Current time
// take the time in the database, the field is of type varChar
try
{
conn.Open ();
aa = Convert.ToDateTime (comm.ExecuteScalar (). ToString ()); // Database time, convert object to string and convert to DateTime
conn.Close ();
}
catch (Exception exp)
{
throw exp;
}
finally
{
conn.Dispose ();
comm.Dispose ();
}
this.HLOldDt.Text = aa.ToString (); // Time in database
bb = System.DateTime.Now; // Current time
this.HLNowDt.Text = bb.ToString (); // output the current time
//jet lag
string ss = this.DateDiff (aa, bb);
this.HLSe.Text = ss.ToString (); // output time difference
}
}
try
{
TimeSpan ts1 = new TimeSpan (DateTime1.Ticks);
TimeSpan ts2 = new TimeSpan (DateTime2.Ticks);
TimeSpan ts = ts1.Subtract (ts2) .Duration (); // Find the absolute value of the time difference
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.