void main()
{
struct timeval tp;
gettimeofday(&tp);
printf("second:%ld\n", tp.tv_sec); // 秒
printf("Microseconds:%ld\n", tp.tv_usec); // 微妙
// 需要#include <time.h>头文件
struct timespec timestamp;
clock_gettime(CLOCK_REALTIME, ×tamp);
printf("second:%ld\n", timestamp.tv_sec); // 秒
printf("nanosecond:%ld\n", timestamp.tv_nsec); // 纳秒
}
参考链接:
C语言:获取精度为纳秒的时间戳