可以在strftime函数设置需要的时间格式
//时间戳转化为时间
std::string convertTime(long long timestamp)
{
time_t tick = (time_t)(timestamp / 1000);//转换时间
struct tm tm;
char s[40];
tm = *localtime(&tick);
strftime(s, sizeof(s), "%Y-%m-%d", &tm);
std::string str(s);
return str;
}
输入
1669100980
输出
2022-11-22