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; }
相关文章推荐
- Windows下直接使用gettimeofday函数
- gettimeofday windows上的实现
- gettimeofday windows上的实现
- windows下实现gettimeofday
- gettimeofday和clock_gettime的不同
- gettimeofday
- Linux 中的计时——gettimeofday函数
- Linux时间操作(time、gettimeofday)
- C语言函数gettimeofday
- time,gettimeofday,clock_gettime,_ftime
- linux 上时间相关的函数 time ,_ftime , gettimeofday, clock_gettime
- ios里gettimeofday用法
- gettimeofday()
- Linux系统调用--gettimeofday/settimeofday函数详解
- gettimeofday和clock_gettime的不同
- gettimeofday
- gettimeofday()
- 微秒级计时 gettimeofday
- Linux 中的计时——gettimeofday函数
- Linux时间函数之gettimeofday()函数之使用方法