怎样去调用这段代码?
网上找的时间计算 "计算两个日期之间时间 "..可怎么调用它呢,谢谢!
private 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;
}
------解决方案--------------------DateTime DateTime1=DateTime.Parse( '2007-6-11 00:10:10 ');
DateTime DateTime2=DateTime.Parse( '2007-6-12 01:10:10 ');
DateDiff(DateTime1, DateTime2)
------解决方案--------------------private void JB_jisuan1_Click(object sender, System.EventArgs e)
{
DateTime DateTime1=DateTime.Parse( '2007-6-11 00:10:10 ');
DateTime DateTime2=DateTime.Parse( '2007-6-12 01:10:10 ');
string a = DateDiff(DateTime1, DateTime2);
response.write(a);
}
------解决方案--------------------这个函数就是你传入2个DateTime的参数,他计算好差值之后返回这个值的String 类型。