话不多说,直接上代码
#include <time.h>
#include<iostream>
int main()
{
time_t t = time(0);
char tmp[32] = { NULL };
strftime(tmp, sizeof(tmp), "%Y-%m-%d %H:%M:%S", localtime(&t));
std::string date(tmp);
std::cout<<date<<std::endl;
return 0;
}