C语言获取时间戳秒毫秒微秒
所属分类 c
浏览量 976
Second, Millisecond(毫秒), Microsecond(微秒)
gettimeofday()
struct timeval {
// seconds since Jan. 1, 1970
time_t tv_sec;
// and microseconds
suseconds_t tv_usec;
};
#include "stdio.h"
#include "sys/time.h"
// for sleep
#include "unistd.h"
void showtime(){
struct timeval tv;
gettimeofday(&tv,NULL);
printf("second :%ld\n",tv.tv_sec);
printf("millisecond:%ld\n",tv.tv_sec*1000 + tv.tv_usec/1000);
printf("microsecond:%ld\n",tv.tv_sec*1000000 + tv.tv_usec);
}
int main(){
showtime();
printf("\n");
sleep(1);
showtime();
return 0;
}
second :1631610949
millisecond:1631610949920
microsecond:1631610949920783
second :1631610950
millisecond:1631610950921
microsecond:1631610950921375
上一篇
下一篇
Java实现简单的模板
Linux可执行文件信息查看
C语言获取时间戳秒
java 和 C 循环和递归性能比较
C++11 chrono 获取时间戳
C语言字符串转浮点数