Featured image of post [C++20] Simple Code Example for Outputting Current Time in ISO8601 Format (UTC)

[C++20] Simple Code Example for Outputting Current Time in ISO8601 Format (UTC)

A must-see for engineers who want to output the current time in the global standard ISO8601 format using C++! This article clearly introduces code examples utilizing C++20's std::format and chrono library to smartly and concisely perform time format conversion.

Prerequisites

  • ISO C++ 20 Standard (/std:c++20)

Code

1
2
3
4
#include <chrono>
#include <format>

std::string datetime = std::format("{:%FT%TZ}", system_clock::now());

That’s how to output the current time in ISO8601 format in C++.

References

comments powered by Disqus