时间函数,真的不知道怎办啊
我知道可以用 time() time32() time64()
获取当前系统距离UTC的时间,单位为毫秒
但是我想获得精度到微妙的时间。貌似没有函数可以获取现在的微妙时间。
我网上找了很久,只是发现了有个 gettimeofday 用这个可以获取当前的秒以及微妙
但是在MSDN上找不到,貌似不是WINDOWS或VC下面的函数。没办法用。
那我要怎么样才能得到毫秒和微秒啊。不知道怎么办啊
[解决办法]
获得高精度的时间
http://blog.csdn.net/mazheng1989/article/details/7096859
[解决办法]
GetSystemTimeAsFileTime
The GetSystemTimeAsFileTime function obtains the current system date and time. The information is in Coordinated Universal Time (UTC) format.
VOID GetSystemTimeAsFileTime(
LPFILETIME lpSystemTimeAsFileTime // pointer to a file time
// structure
);
Parameters
lpSystemTimeAsFileTime
Pointer to a FILETIME structure to receive the current system date and time in UTC format.
Return Values
This function does not return a value.
Remarks
The GetSystemTimeAsFileTime function is equivalent to the following code sequence:
FILETIME ft;
SYSTEMTIME st;
GetSystemTime(&st);
SystemTimeToFileTime(&st,&ft);
QuickInfo
Windows NT: Requires version 3.5 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in winbase.h.
Import Library: Use kernel32.lib.
See Also
Time Overview, Time Functions, FILETIME, GetSystemTime, SYSTEMTIME, SystemTimeToFileTime
FILETIME
The FILETIME structure is a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601.
typedef struct _FILETIME { // ft
DWORD dwLowDateTime;
DWORD dwHighDateTime;
} FILETIME;
Members
dwLowDateTime
Specifies the low-order 32 bits of the file time.
dwHighDateTime
Specifies the high-order 32 bits of the file time.
Remarks
It is not recommended that you add and subtract values from the FILETIME structure to obtain relative times. Instead, you should
Copy the resulting FILETIME structure to a LARGE_INTEGER structure.
Use normal 64-bit arithmetic on the LARGE_INTEGER value.
[解决办法]
windows平台 排名第一 明显是 QueryPerformanceCounter系列 精度可以到大约600微妙.
高精度也会带来高消耗. 请酌情使用.
[解决办法]
windows 平台 毫秒级 最常用的 应该是 GetTickCount
[解决办法]
微秒用QueryPerformanceCounter/KeQueryPerformanceCounter。
毫秒用GetTickCount/timeGetTime。
[解决办法]