直接上,
#include <iostream>
#include <string>
using namespace std;
static string getCurrentTime()
{
time_t t = time(NULL);
char ch[64] ={0};
strftime(ch,sizeof(ch) -1,"%Y-%m-%d %H:%M:%S",localtime(&t));
return ch;
}
int main(int argc, char const *argv[])
{
cout << getCurrentTime() << endl;
return 0;
}