Qt文档中关于QTime::currentTime()
的说明:
请注意,精度取决于基础操作系统的精度,不是所有系统都提供1毫秒的精度。
但在Windows 7中有没有办法以毫秒精度获取此时间?
您可以使用QDateTime
类,并使用适当的格式转换当前时间:
QDateTime::currentDateTime().toString("yyyy/MM/dd hh:mm:ss,zzz")
其中'z'对应毫秒精度。
您可以在C/C++中使用time.h头文件提供的功能。
#include <time.h>
clock_t start, end;
double cpu_time_used;
int main()
{
start = clock();
/* Do the work. */
end = clock();
cpu_time_used = ((double)(end-start)/ CLOCKS_PER_SEC);
}
GetSystemTimePreciseAsFileTime
可提供小于1微秒的系统时间分辨率。