获取时间戳,以秒,毫秒,微妙为单位

#include <sys/time.h>
long long PC::GetCurTime_2()
{
struct timeval tv;
gettimeofday(&tv, NULL);
// printf(“second:%ld\n”,tv.tv_sec); //秒
// printf(“millisecond:%ld\n”,tv.tv_sec1000 + tv.tv_usec/1000); //毫秒
// printf(“microsecond:%ld\n”,tv.tv_sec
1000000 + tv.tv_usec); //微秒
long long temp_time = tv.tv_sec * 1000000 + tv.tv_usec;
return temp_time;
}

猜你喜欢

转载自blog.csdn.net/weixin_43466192/article/details/121717702