1 /* 2 * From http://www.openasthra.com/c-tidbits/gettimeofday-function-for-windows/ 3 */ 4 #include "gettimeofday.h" 5 gettimeofday(struct timeval * tv,struct timezone * tz)6int gettimeofday(struct timeval *tv, struct timezone *tz) 7 { 8 FILETIME ft; 9 unsigned __int64 tmpres = 0; 10 static int tzflag = 0; 11 12 if (NULL != tv) 13 { 14 GetSystemTimeAsFileTime(&ft); 15 16 tmpres |= ft.dwHighDateTime; 17 tmpres <<= 32; 18 tmpres |= ft.dwLowDateTime; 19 20 tmpres /= 10; /*convert into microseconds*/ 21 /*converting file time to unix epoch*/ 22 tmpres -= DELTA_EPOCH_IN_MICROSECS; 23 tv->tv_sec = (long)(tmpres / 1000000UL); 24 tv->tv_usec = (long)(tmpres % 1000000UL); 25 } 26 27 if (NULL != tz) 28 { 29 if (!tzflag) 30 { 31 _tzset(); 32 tzflag++; 33 } 34 tz->tz_minuteswest = _timezone / 60; 35 tz->tz_dsttime = _daylight; 36 } 37 38 return 0; 39 } 40