1.给一个datetime加12个小时:
public DateTime timeFormat (DateTime datePM)
{
TimeSpan toformat = new TimeSpan(0,12,0,0); //(天,时,分,秒)
DateTime trueDate = datePM.Add(toformat);
return trueDate;
}
2.比较2个datetime大小,返回相差 多少天多少时多少分多少秒
public bool calculatorTime(DateTime errordate,DateTime now,string way)
{
string dateDiff = null;
try
{
TimeSpan ts1 = new TimeSpan(errordate.Ticks);
TimeSpan ts2 = new TimeSpan(now.Ticks);
TimeSpan ts = ts2.Subtract(ts1).Duration(); //subtract相减
ts.Days;
ts.Hours;
ts....;
ts....;