.NET 精确计算时间差
//获取系统启动后的毫秒数
[DllImport("kernel32.dll")]
public static extern uint GetTickCount();
//精确获取时差,使用DateTime.Now.Ticks
new Thread(() =>
{
var dateTime = DateTime.Now.Ticks;
var dateTimeUtc = DateTime.UtcNow.Ticks;
var ystart = Environment.TickCount;
while (!IsDisposed)
{
var dateTime2 = DateTime.Now.Ticks;
var dateTimeUtc2 = DateTime.UtcNow.Ticks;
var yend = Environment.TickCount;
Console.WriteLine("date:{0} date2:{1} tick:{2}", (dateTime2-dateTime)/ TimeSpan.TicksPerMillisecond, (dateTimeUtc2-dateTimeUtc)/ TimeSpan.TicksPerMillisecond,
yend-ystart);
Thread.Sleep(1);
}
}).Start();