#include <chrono>
static void printTime(const std::string& label)
{
auto now = std::chrono::system_clock::now();
//通过不同精度获取相差的毫秒数
uint64_t dis_millseconds =
std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count() -
std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count() * 1000;
time_t tt = std::chrono::system_clock::to_time_t(now);
auto time_tm = localtime(&tt);
char strTime[25] = { 0 };
sprintf(strTime, " %02d:%02d:%02d %03d", time_tm->tm_hour, time_tm->tm_min, time_tm->tm_sec,
(int)dis_millseconds);
std::cout << label << strTime << std::endl;
}
C++标准库输出时间
最新推荐文章于 2024-08-05 09:32:34 发布