首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

时间函数,真的不知道怎办啊解决思路

2012-05-16 
时间函数,真的不知道怎办啊我知道可以用 time() time32() time64()获取当前系统距离UTC的时间,单位为毫秒

时间函数,真的不知道怎办啊
我知道可以用 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。
[解决办法]

探讨

FILETIME

MSDN 上称,FILETIME采用 64 位数值表示与 UTC 时间 1601 年 1 月 1 日 0 时起百纳秒的时间间隔

就是说值是纳秒的100被

1秒 = 1000毫秒
1毫秒 = 1000微妙
1微秒 = 1000纳秒

也就是说,我可以通过这个值来取得精度达到 0.1 微妙, 100纳秒 的时间值。

为什么不是1纳秒 而是100……

热点排行