作用

链接

编译器版本支持

g++版本至少是13。

g++ --version

升级g++编译器

案例

时间格式化

#include <iostream>
#include <chrono>
#include <format> // C++20 <format> 库

int main() {
    // 获取当前时间(UTC)
    auto now = std::chrono::system_clock::now();
    
    // 格式化为 ISO 8601 字符串(如 "2025-08-07T12:34:56.789Z")
    std::string time_str = std::format("{:%Y-%m-%dT%H:%M:%S.%Z}", now);
    
    std::cout << time_str << std::endl;
    return 0;
}

Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐