如何将此功能从linux转换为Windows?我无法使用gettimeofday函数
double getSysTime() {
struct timeval tp; gettimeofday(&tp,NULL);
return double(tp.tv_sec) + double(tp.tv_usec)/1E6;
}
答案 0 :(得分:2)
使用http://support.microsoft.com/kb/167296中提供的示例:
double getSysTime() {
FILETIME time;
int64_t now;
GetSystemTimeAsFileTime(&time);
now = ((LONGLONG) time.dwHighDateTime) << 32 | time.dwLowDateTime;
now = now - 116444736000000000;
/* (now * 100) is number of nanoseconds since Unix epoch */
return ((double) now) / 1e7;
}