tzdb struct

Represents a copy of the time zone database.

Syntax

struct tzdb; // C++20

Remarks

Represents a copy of the IANA (Internet Assigned Numbers Authority) time zone database. The database contains information about each time zone and its history of local time adjustments. For more information about the database, see Time Zone Database.

Members

Member Description
leap_seconds A sorted vector<leap_second>. A leap_second provides a history of when leap seconds were added in the past.
links A sorted vector<time_zone_link>. A time_zone_link provides the alternate name for a given time zone.
version A std::string containing the database version.
zones A sorted vector<time_zone>. A time_zone has the full history of time zone rules for a particular area.

For an example of how to use these members, see Example: leap_seconds, links, zones near the end of this topic.

Member functions

Name Description
current_zone Gets the local time zone.
locate_zone Gets the specified time zone.

current_zone

Gets the computer's local time zone.

time_zone* current_zone() const; // C++20

Return value

A pointer to the time_zone that represents the local time zone of the computer.

Example: current_zone

This example demonstrates getting the current time zone.

// compile using: /std:c++latest
#include <iostream>
#include <chrono>

using namespace std::chrono;

int main()
{
    auto& db = get_tzdb();
    std::cout << "Current zone: " << db.current_zone()->name();
    
    return 0;
}
Current zone: America/Los_Angeles

locate_zone

Gets the specified time zone.

const time_zone* locate_zone(string_view name) const;

Example: locate_zone

This example demonstrates getting a time zone by name.

// compile using: /std:c++latest
#include <iostream>
#include <chrono>

using namespace std::chrono;

int main()
{
    auto& db = get_tzdb();
    std::cout << "Locate zone : " << db.locate_zone("America/New_York")->name() << "\n";
    
    return 0;
}
Locate zone : America/New_York

This example demonstrates using various tzdb data members.

// compile using: /std:c++latest
#include <iostream>
#include <chrono>

using namespace std::chrono;

int main()
{
    std::cout << "Leap seconds:\n";
    std::for_each(db.leap_seconds.begin(), db.leap_seconds.end(),
        [](const leap_second& ls)
        {
            std::cout << ls.date() << "\n";
        });

    std::cout << "Links:\n";
    std::for_each(db.links.begin(), db.links.end(),
        [](const time_zone_link& l)
        {
            std::cout << "Name: " << l.name() << "\t\tTarget:" << l.target() << '\n';
        });

    std::cout << "\nTime Zone descriptions:\n";
    std::for_each(db.zones.begin(), db.zones.end(),
        [](const time_zone& z)
        {
            std::cout << "Zone: " << z.name() << "\n";
        });
    
    return 0;
}
Leap seconds:
1972-07-01 00:00:00
1973-01-01 00:00:00
1974-01-01 00:00:00
...
Links:
Name: ACT               Target:Australia/Darwin
Name: AET               Target:Australia/Sydney
Name: AGT               Target:America/Buenos_Aires
Name: ART               Target:Africa/Cairo
...
Time Zone descriptions:
Zone: Africa/Abidjan
Zone: Africa/Accra
Zone: Africa/Addis_Ababa
...

Requirements

Header: <chrono>

Namespace: std::chrono

Compiler Option: /std:c++latest

See also

<chrono>
tzdb_list
time_zone_link
Header Files Reference