1 #include <string> 2 #include <time.h> 3 using namespace std; 4 5 string getTime() 6 { 7 time_t timep; 8 time (&timep); 9 char tmp[64]; 10 strftime(tmp, sizeof(tmp), "%Y-%m-%d %H:%M:%S",localtime(&timep) ); 11 return tmp; 12 } 13 14 int main(){ 15 string time = getTime(); 16 cout << time << endl; 17 18 return 0; 19 }
输出结果为: