您的位置:首页 > 其它

windows gettimeofday

2016-11-21 15:59 423 查看
#include <stdio.h>
#include <time.h>
#include <stdint.h>

#ifdef _WIN32
#include <Windows.h>
#else
#include <unistd.h>
#endif

void gettimeofday(struct timeval *tp)
{
uint64_t  intervals;
FILETIME  ft;

GetSystemTimeAsFileTime(&ft);

/*
* A file time is a 64-bit value that represents the number
* of 100-nanosecond intervals that have elapsed since
* January 1, 1601 12:00 A.M. UTC.
*
* Between January 1, 1970 (Epoch) and January 1, 1601 there were
* 134744 days,
* 11644473600 seconds or
* 11644473600,000,000,0 100-nanosecond intervals.
*
* See also MSKB Q167296.
*/

intervals = ((uint64_t) ft.dwHighDateTime << 32) | ft.dwLowDateTime;
intervals -= 116444736000000000;

tp->tv_sec = (long) (intervals / 10000000);
tp->tv_usec = (long) ((intervals % 10000000) / 10);
}

static long _getTime(void)
{
struct timeval  now;
#ifdef _WIN32
gettimeofday(&now);
#else
gettimeofday(&now,NULL);
#endif
return (long)(now.tv_sec*1000 + now.tv_usec/1000);
}

int main()
{

//printf("%d\n",sizeof(CTest));
printf("%lld\n",_getTime());

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: