std::string current_time_stamp()
{
std::time_t now = std::time(NULL);
std::tm* ptm = std::localtime(&now);
char buff[100];
std::strftime(buff,32,"%Y-%m-%d %H:%M%s",ptm);
return string(buff);
}
本文介绍了一个简单的C++函数,用于获取格式化的当前时间戳。该函数利用了C++标准库中的`std::time`和`std::localtime`来获取当前时间,并使用`std::strftime`将时间格式化为字符串。
std::string current_time_stamp()
{
std::time_t now = std::time(NULL);
std::tm* ptm = std::localtime(&now);
char buff[100];
std::strftime(buff,32,"%Y-%m-%d %H:%M%s",ptm);
return string(buff);
}
1万+
1875
766

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