# Around the World in C++: Exploring Time Zones with std::chrono

DevFeed: [Around the World in C++: Exploring Time Zones with std::chrono](<https://devfeed.tech/articles/around-the-world-in-c-exploring-time-zones-with-std-chrono-53306.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2024/zones_around_world_chrono/>)

Published: 2024-11-10T00:00:00Z

Content type: tutorial

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Library](<https://devfeed.tech/topics/library.md>), [Database](<https://devfeed.tech/topics/database.md>)

Tags: [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [c-plus-plus-23](<https://devfeed.tech/tags/c-plus-plus-23.md>), [code](<https://devfeed.tech/tags/code.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [database](<https://devfeed.tech/tags/database.md>), [library](<https://devfeed.tech/tags/library.md>), [programming](<https://devfeed.tech/tags/programming.md>)

## AI overview

A tutorial on using C++20's std::chrono time-zone support to inspect the IANA Time Zone Database and identify unusual offsets and daylight-saving rules. It examines examples including Nepal's UTC+5:45 offset and Lord Howe Island's 30-minute daylight-saving adjustment.

## Source excerpt

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. We'll use GCC 14.2 as it fully supports C++20 chrono and also std::print from 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 tzdb class: namespace std::chrono { struct tzdb { string version; // IANA time zone database version vector<time_zone> zones; // Time zone container vector<time_zone_link> links; // Alternative names vector<leap_second> leap_seconds; // Leap second info }; } Essential aspects of the database: It's read-only - users cannot construct or modify a tzdb Access is provided through two global functions: get_tzdb(): Returns the current database get_tzdb_list(): Returns the list of available database versions Here's how to access the database: #include <chrono> #include <print> #include <cassert> int main() { const auto& db = std::chrono::get_tzdb(); std::print("Current DB version: {}\n", db.version); const auto& db_list = std::chrono::get_tzdb_list(); auto size = std::distance(db_list.begin(), db_list.end()); std::print("Available versions: {}\n", size); assert(&db_list.front() == &db); } See at Compiler Explorer The database provides several key components: Zones (db.zones): Primary container of time zone information Each zone contains complete historical and current rules Examples: "America/New_York", "Europe/London" Links (db.links): Alternative names for existing zones Useful for backward compatibility Example: "EST" links to "America/New_York" Leap Seconds (db.leap_seconds): Records