c++ date format yyyymmdd

C++ 支持各种日期格式,其中一种是 yyyymmdd。您可以使用 C++ STL 中的 std::put_time() 函数来格式化日期。例如:

#include <iostream>
#include <iomanip>
#include <ctime>
int main()
    std::time_t t = std::time(nullptr);
    std::tm tm = *std::localtime(&t);
    std::cout << std::put_time(&tm, "%Y%m%d") << '\n';

执行此代码将输出当前日期,并以 yyyymmdd 格式显示。

  •