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 }

输出结果为:

posted on 2017-04-25 14:53  Daniel_z  阅读(45235)  评论(0编辑  收藏  举报