gettimeofday,如何翻译linux函数

时间:2015-01-29 23:46:19

标签: c++ linux windows time

如何将此功能从linux转换为Windows?我无法使用gettimeofday函数

  double getSysTime() {
    struct timeval tp; gettimeofday(&tp,NULL); 
    return double(tp.tv_sec) + double(tp.tv_usec)/1E6; 
  }

1 个答案:

答案 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;
}