Dean
Dean

Reputation: 6950

gettimeofday, how to translate a linux function

How can I translate this function from linux to Windows? I can't use the gettimeofday function

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

Upvotes: 1

Views: 240

Answers (1)

myaut
myaut

Reputation: 11494

Using examples given in 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;
}

Upvotes: 2

Related Questions