求助!请问一个c#中计算时间间隔的问题! 我用DateTime.Now获得了两个时间用什么办法计算这两个时间的间隔?要精确到毫秒希望有人能帮帮我,指点我一下谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 DateTime t1 = DateTime.Now;...DateTime t2 = DateTime.Now;TimeSpan dt = t2 - t1; DateTime t1 = DateTime.Now;...DateTime t2 = DateTime.Now;TimeSpan dt = t2 - t1;Console.WriteLine(dt); DateTime t1 = DateTime.Now; Thread.Sleep(1234); DateTime t2 = DateTime.Now; TimeSpan ts=t2-t1; MessageBox.Show(ts.TotalMilliseconds.ToString()); 用api time?time(有点击不住了) 两个一减就行了 上面答案都有了,只是注意对于需要精度的地方,尽量不要做类型转换,比如转个int转个long的。就算int转long都会产生误差的。 可能是菜鸟的问题 C# vs C++/CLI dispose 关于关闭窗口后的问题 vs2005 c# 如何才能 使用 sqlce2.0 不用sqlce3.0 C#怎么读取和写入INI的配置信息? 一个B/S模式下按钮控制的问题 水晶报表许可证号问题 从那里里可以弄到VS.NET的安装盘??? 急求 xsl的问题? C#程序画的图形怎样按一定角度旋转 代码写在哪里好呢? 在web datagrid 中怎样知道单击到的单元格的行与列
...
DateTime t2 = DateTime.Now;
TimeSpan dt = t2 - t1;
...
DateTime t2 = DateTime.Now;
TimeSpan dt = t2 - t1;
Console.WriteLine(dt);
Thread.Sleep(1234);
DateTime t2 = DateTime.Now;
TimeSpan ts=t2-t1;
MessageBox.Show(ts.TotalMilliseconds.ToString());
只是注意对于需要精度的地方,尽量不要做类型转换,比如转个int转个long的。就算int转long都会产生误差的。