Around the World in C++: Exploring Time Zones with std::chrono -- Bartlomiej Filipek
While most time zones use simple hour offsets from UTC, some regions have chosen unusual time differences. In this blog post, we’ll explore how we can discover such zones using C++20’s chrono library.
Around the World in C++: Exploring Time Zones with std::chrono
by Bartlomiej Filipek
From the article:
We’ll use GCC 14.2 as it fully supports C++20 chrono and also
std::printfrom C++23.First Attempt: Basic Zone Iteration
C++20 introduced comprehensive time zone support through the
<chrono>library. The implementation relies on the IANA Time Zone Database (also known as the “tz database” or “zoneinfo”), which is the de facto standard for time zone information used by most operating systems and programming languages.The Time Zone Database
In C++20, the time zone database is represented by the
tzdbclass:


In this blog post, we will explore handling dates using std::chrono, including time zones. We’ll utilize the latest features of the library to retrieve the current time across various time zones, taking into account daylight saving time changes as well. Additionally, we will incorporate new capabilities introduced in C++23, such as enhanced printing functions and more.
Recent versions of the C++ language (C++20 and C++23) may allow you to change drastically how you program in C++. I want to provide some fun examples.
Programming at compile time has been possible in C++ for a long time. Wu Yongwei considers its past, present and future.