#include <time.h>
#include <stdio.h>
int main()
{
time_t tt=time(NULL);
tm* t=localtime(&tt);
// printf("%4d-%2d-%d %2d-%2d-%2d\n",t->tm_year+1900,
// t->tm_mon+1,
// t->tm_mday,
// t->tm_hour,
// t->tm_min,
// t->tm_sec);
char time[24];
sprintf(time,"%4d-%2d-%d %2d-%2d-%2d\n",t->tm_year+1900,
t->tm_mon+1,
t->tm_mday,
t->tm_hour,
t->tm_min,
t->tm_sec);
printf("%s",time);
}
详细:https://blog.csdn.net/weixin_43627118/article/details/90515471
参考:https://www.cnblogs.com/cppentry/archive/2020/02/25/12364644.html