timeval uSeconds(){ static const DWORDLONG FILETIME_to_timval_skew=116444736000000000; FILETIME tfile; ::GetSystemTimeAsFileTime (&tfile);
ULARGE_INTEGER _100ns; _100ns.LowPart = tfile.dwLowDateTime; _100ns.HighPart = tfile.dwHighDateTime; _100ns.QuadPart -= FILETIME_to_timval_skew; // Convert 100ns units to seconds; timeval timenow;
ULARGE_INTEGER largeint; largeint.QuadPart=_100ns.QuadPart / (10000 * 1000);
// Convert 100ns units to seconds; timenow.tv_sec = (long) (_100ns.QuadPart / (10000 * 1000)); // Convert remainder to microseconds; timenow.tv_usec = (long) ((_100ns.QuadPart % (10000 * 1000)) / 10);
return timenow;}
Windows下精确到微秒的系统时间获取
参考: Windows下精确到微秒的系统时间获取_window.microtimestamp-CSDN博客