Prerequisites
- ISO C++ 20 Standard (/std:c++20)
Code
This example formats UTC to whole-second precision, for example 2026-11-23T00:00:00Z.
| |
%Fformats the date and%Tthe time. TheTandZin the format string are literal characters; thesystem_clocktime point is formatted as UTC. Fractional seconds may appear if the time point has subsecond precision. Chrono formatting is a C++20 library feature, but implementation support varies by standard library. Check the compiler and library you use.
![Featured image of post [C++20] Format the Current Time as UTC ISO 8601 with std::chrono and std::format](/p/c-%E3%81%A7%E7%8F%BE%E5%9C%A8%E6%99%82%E5%88%BB%E3%82%92iso8601%E3%83%95%E3%82%A9%E3%83%BC%E3%83%9E%E3%83%83%E3%83%88%E3%81%A7%E5%87%BA%E5%8A%9B%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95/img_hu14325398801108400926.webp)