Linux获取系统当前时间
程序员文章站
2022-07-15 17:19:56
...
#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);
}