C get system time to microsecond accuracy on windows?

c, c++, windows

Solution

Look at GetSystemTimeAsFileTime

It gives you accuracy in 0.1 microseconds or 100 nanoseconds.

Note that it's Epoch different from POSIX Epoch.

So to get POSIX time in microseconds you need:

    FILETIME ft;
    GetSystemTimeAsFileTime(&ft);
    unsigned long long tt = ft.dwHighDateTime;
    tt <<=32;
    tt |= ft.dwLowDateTime;
    tt /=10;
    tt -= 11644473600000000ULL;

So in such case `time(0) == tt / 1000000`

Problem

Possible Duplicate: measuring time with resolution of microseconds in c++? Hi, Is there a simple way i can get the system time on a Windows machine, down to microsecond accuracy?

Original source

Related problems