homework.beginTime 你定义的是什么类型,日期,那就传入一个datetime类型的数据
应该是2个时间相减的数
private void timer2_Tick(object sender, EventArgs e) { string NowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); DateTime begintime = Convert.ToDateTime(m_DemoSingleton.WorkBeginTime); DateTime endtime = Convert.ToDateTime(NowTime); TimeSpan ts_begin = new TimeSpan(begintime.Ticks); TimeSpan ts_end = new TimeSpan(endtime.Ticks); TimeSpan ts = ts_end.Subtract(ts_begin).Duration(); tsCountTime.Text = ts.Days.ToString() + "天" + ts.Hours.ToString() + "小时" + ts.Minutes.ToString() + "分钟" + ts.Seconds.ToString() + "秒"; }