CTimeSpan类可以直接计算时间差

解决方案 »

  1.   

    CTime tm1,tm2;
    CTimeSpan ts;
    .....ts = tm1 - tm2;
      

  2.   

    用::timeGetTime()这个函数获得当前时间
    两次获得即可得到一个时间差;
      

  3.   

    用GetTickCount  API函数,得到执行前后的差值。 
    精度比秒高得多。
     
      

  4.   

    Finds the difference between two times.double difftime( time_t timer1, time_t timer0 );
    difftime returns the elapsed time in seconds, from timer0 to timer1. The value returned is a double-precision floating-point number
      

  5.   

    GetTickCount 时非常精确的,毫秒级的
      

  6.   

    GetTickCount的返回值虽然是以毫秒为单位的,但是实际的精度与系统时钟的分辨率有关,是达不到这个数量级的。下面是msdn的原话。GetTickCount
    The GetTickCount function retrieves the number of milliseconds that have elapsed since the system was started. It is limited to the resolution of the system timer. To obtain the system timer resolution, use the GetSystemTimeAdjustment function. 真要精度的话,应该用多媒体定时器函数,timeGetTime,它的精度大约在5个毫秒左右,如果要求更高的话,应该用QueryPerformanceCounter和QueryPerformanceFrequency。我觉得用什么主要看你的需要吧,如果只是到秒级的话,用CTime足够了。
      

  7.   

    hooligan(风) 说的没错,那样就完全可以了!想要提高精度可以对系统的Timer进行设置,因为8253缺省分值是65536,就是一秒18.2个tick啦,不过想改8253需要自己写个DRIVER了。可以精确到10万分之一秒以上。