版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wushuangge/article/details/81019118
#include <time.h>
void get_time()
{
timespec time;
clock_gettime(CLOCK_REALTIME, &time); //获取相对于1970到现在的秒数
tm nowTime;
localtime_r(&time.tv_sec, &nowTime);
char current[1024];
sprintf(current, "%04d%02d%02d%02d:%02d:%02d", nowTime.tm_year + 1900, nowTime.tm_mon+1, nowTime.tm_mday,
nowTime.tm_hour, nowTime.tm_min, nowTime.tm_sec);
}