#include <sys/time.h>
unsigned int GetTickCount()
{
struct timeval tv;
if(gettimeofday(&tv, 0))
return 0;
return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
}
本文提供了一个简单的C函数GetTickCount(),该函数使用系统调用gettimeofday()来获取当前时间,并将其转换为毫秒单位返回。这对于需要精确计时的应用场景非常有用。
#include <sys/time.h>
unsigned int GetTickCount()
{
struct timeval tv;
if(gettimeofday(&tv, 0))
return 0;
return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
}

被折叠的 条评论
为什么被折叠?