Spec-Zone.ru › C++

std::chrono::locate_zone

Defined in header <chrono>
const std::chrono::time_zone* locate_zone( std::string_view tz_name );
(since C++20)

Convenience function for locating a time zone in the time zone database. Equivalent to std::chrono::get_tzdb().locate_zone(tz_name).

Parameters

tz_name - a time zone name to locate

Exceptions

std::runtime_error if the specified time zone cannot be found, or if this is the first reference to the time zone database and the time zone database cannot be initialized.

Notes

A call to this function that is the first reference to the time zone database will cause it to be initialized.

Example

#include <chrono>
#include <iostream>

int main()
{
    try
    {
        for (const auto zone : {"Atlantic/Bermuda", "Alcatraz"})
            std::cout << std::chrono::locate_zone(zone)->name() << '\n';
    }
    catch(const std::runtime_error& ex)
    {
        std::cout << ex.what() << '\n';
    }
}

Possible output:

Atlantic/Bermuda
std::chrono::tzdb: cannot locate zone: Alcatraz

See also

locate_zone
locate a time zone with the given name
(public member function of std::chrono::tzdb)
get_tzdbget_tzdb_listreload_tzdbremote_version
(C++20)
accesses and controls the global time zone database information
(function)

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/chrono/locate_zone

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API