计算两个时间差

    public static string DateDiff(DateTime DateTime1, DateTime DateTime2)
    {
        string dateDiff = "";
        TimeSpan ts1 = new TimeSpan(DateTime1.Ticks);
        TimeSpan ts2 = new TimeSpan(DateTime2.Ticks);
        TimeSpan ts = (TimeSpan)(ts2 - ts1); 
        if (Convert.ToInt32(ts.Days.ToString()) < 0)
           dateDiff = "<font color=red>已经过期</font>";
        else
            dateDiff = ts.Days.ToString()+"天";
        return dateDiff;
    }

你可能感兴趣的:(时间)