写的太复杂了。
[C#] 纯文本查看 复制代码 /// <summary>
/// 获取两时间差的元组
/// </summary>
/// <param name="DateTime1"></param>
/// <param name="DateTime2"></param>
/// <returns></returns>
public static Tuple<int, int, int, int> DateDiff(DateTime DateTime1, DateTime DateTime2)
{
Tuple<int, int, int, int> tuple = null;
try
{
TimeSpan ts1 = new TimeSpan(DateTime1.Ticks);
TimeSpan ts2 = new TimeSpan(DateTime2.Ticks);
TimeSpan ts = ts1.Subtract(ts2).Duration();
tuple = new Tuple<int, int, int, int>(ts.Days, ts.Hours, ts.Minutes, ts.Seconds);
}
catch
{
}
return tuple;
}
Tuple<int, int, int, int> tuple = DateTimeUtil.DateDiff(Convert.ToDateTime(lastTime), DateTime.Now);
sec = tuple.Item1 * 24 * 60 * 60 + tuple.Item2 * 60 * 60 + tuple.Item3 * 60 + tuple.Item4;
|