时间戳格式化生成毫秒级

std::string millisecond_to_str(const std::int64_t &milliseconds)
{
    std::chrono::milliseconds ms(milliseconds);
    std::chrono::time_point<std::chrono::high_resolution_clock, std::chrono::milliseconds> t1(ms);
    std::time_t t = std::chrono::system_clock::to_time_t(t1);

    std::stringstream ss;
    auto const msecs = ms.count() % 1000;
    ss << std::put_time(std::localtime(&t), "%Y-%m-%d %H.%M.%S") << "." << msecs;
    return ss.str();
}

 

posted @ 2023-07-18 15:09  浅情1314  阅读(77)  评论(0编辑  收藏  举报