0
点赞
收藏
分享

微信扫一扫

Linux c++获取当前系统时间并格式化输出

践行数据分析 2022-09-15 阅读 99


#include <string>
#include <time.h>
#include <iostream>

using namespace std;

string getTime()
{
time_t timep;
time (&timep);
char tmp[64];
strftime(tmp, sizeof(tmp), "%Y-%m-%d %H:%M:%S",localtime(&timep));
return tmp;
}

int main(){
string time = getTime();
cout << time << endl;

return 0;
}


编译:g++ date.cpp -o date

执行:./date

结果:2019-09-09 17:06:32

举报

相关推荐

0 条评论