1.概要
c++ 时间格式化
2.代码
#include <iostream>
#include <string>
#include <time.h>
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;
std::cout << "Hello World!\n";
}
3.运行

4.使用环境
vs2019
5.备注

本文介绍如何使用C++的time库和strftime函数来格式化当前时间,提供了详细的代码示例,并以VS2019为环境。
4221

被折叠的 条评论
为什么被折叠?



