计算两个日期时间差

protected void Button1_Click(object sender, EventArgs e)

    {

        DateTime dt1 = Convert.ToDateTime("2007-3-24 11:29:12");

        DateTime dt2 = Convert.ToDateTime("2007-2-24 10:29:12");

        TimeSpan ts = dt1 - dt2;



        string timespan = "相差:"

        + ts.Days.ToString() + "天"

        + ts.Hours.ToString() + "小时"

        + ts.Minutes.ToString() + "分钟"

        + ts.Seconds.ToString() + "秒";

        Label1.Text = timespan;

    }

你可能感兴趣的:(日期)