标签 本地时间 下的文章

%H 24小时制 %I 12小时制

static std::string SerializeChronoDate(const char* format = "%Y-%m-%d %H:%M:%S") // format = %F %T
{
    char buffer[40] = {};
    {
        if (std::strftime(
            buffer, 
            std::size(buffer), 
            format, 
            std::localtime(std::addressof(static_cast<const std::time_t&>(std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()))))
        ))
        {
            return std::string(buffer, std::size(buffer));
        }
    }

    throw std::runtime_error("failed to get current date as string");
}