請問C++中獲取時間的函數是什么?精度需要到毫秒的﹗
謝謝﹗

解决方案 »

  1.   

    DWORD GetTickCount( void ); Return Values
    The number of milliseconds that have elapsed since the system was started indicates success
      

  2.   

    void GetSystemTime( LPSYSTEMTIME lpSystemTime ); 
    Parameters
    lpSystemTime 
    [out] Pointer to a SYSTEMTIME structure to receive the current system date and time. 
    Return Values
    None.
      

  3.   

    HRESULT CoFileTimeNow(
      FILETIME * lpFileTime  //Pointer to return the structure
    );The FILETIME data structure is a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601.
      

  4.   

    GetSystemTime、GetTickCount、CTime::GetCurrentTime、COleDateTime::GetCurrentTime都可以,但是精度都不是1毫秒,而是50~9毫秒,不同的操作系统版本精度不一样。
      

  5.   

    需要毫秒精度计时直接用long t=GetTickCount(); 需要纳秒精度计时可参考下列程序:
      
    #include <windows.h>
    #include <iostream>
    #include <iomanip> 
    using namespace std; 
    int main() 

        LARGE_INTEGER t1,t2,feq; 
        int b=0; 
        QueryPerformanceFrequency(&feq);//每秒跳动次数 
        QueryPerformanceCounter(&t1);//测前跳动次数 
        for(int i=0;i<100;i++) b++; 
        QueryPerformanceCounter(&t2);//测后跳动次数 
        double d=((double)t2.QuadPart-(double)t1.QuadPart)/((double)feq.QuadPart);//时间差秒 
      std::cout<<setprecision(20)<<showpoint<<std::endl;//小数点表示20位*e-6,已换算为秒 
        std::cout<<d<<std::endl; 
        return 0; 
    }