static void Main(string[] args)
{
string a = DateDiff(DateTime.Parse("2011-10-9 8:0:0"), DateTime .Parse("2011-10-11 8:0:0"));
Console.WriteLine(a);
Console.ReadKey();
}
public static string DateDiff(DateTime DateTime1, DateTime DateTime2)
{
string dateDiff = null;
try
{
TimeSpan ts1 = new TimeSpan(DateTime1.Ticks);
TimeSpan ts2 = new TimeSpan(DateTime2.Ticks);
TimeSpan ts = ts1.Subtract(ts2).Duration();
dateDiff = ts.Days.ToString() + "天" + ts.Hours.ToString() + "小时" + ts.Minutes.ToString() + "分钟" + ts.Seconds.ToString() + "秒";
}
catch
{
}
return dateDiff;
} |