//获取系统启动后的毫秒数
[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();

发表评论

邮箱地址不会被公开。 必填项已用*标注