#include <time.h>
void get_time(std::string& strtime)
{
char buff[20]; // sizeof("2018-04-19 19:49:23") == 20;
time_t now = time(NULL);
tm time;
localtime_s(&time, &now);
strftime(buff, sizeof(buff), "%Y-%m-%d %H:%M:%S", &time);
strtime = buff;
}
string strt;
get_time(strt);
printf("date:%s\n", strt.c_str());
c++格式化时间
最新推荐文章于 2024-08-01 14:38:45 发布