TimeSpan ts1 = new TimeSpan(DateTime.Now.Ticks); //获取当前时间的刻度数
//执行某操作
TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks);
TimeSpan ts = ts2.Subtract(ts1).Duration(); //时间差的绝对值
string spanTotalSeconds = ts.TotalSeconds.ToString(); //执行时间的总秒数
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks);
TimeSpan ts = ts2.Subtract(ts1).Duration(); //时间差的绝对值
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](http://img.zemanta.com/pixy.gif?x-id=d09f60c8-769a-884f-afa8-c7b1b53f2e0a)