description | title | ms.date | f1_keywords | helpviewer_keywords | dev_langs | ||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: time_zone_link class |
time_zone_link class |
05/31/2022 |
|
|
|
Specifies an alternative name for a time_zone
.
class time_zone_link; // Since C++20
time_zone_link
instances are created when the time zone database is initialized. They can't be created directly. Get an instance via get_tzdb().links
, as shown in the example at the end of this topic.
Although this type has a default move constructor and move assignment operator, it isn't copyable because only const
access is provided to this type. Using those functions results in undefined behavior, which is why the move constructor and assignment operator aren't listed here.
Differences with IANA database
In Microsoft's implementation, time zone data can differ in some cases from the Internet Assigned Numbers Authority (IANA) time zone database. For example, "America/Nuuk"
is returned instead of "America/Godthab"
("America/Nuuk"
was renamed "America/Godthab"
in April 2020). We don't supply the "Eastern War Time EWT"
time zone at this time. For more information, see Issue #1786 on the Microsoft STL GitHub repo.
Name | Description |
---|---|
name |
Gets the alternate name for the time zone. |
target |
The name of the time_zone that this time_zone_link is an alternative name for. |
Name | Description |
---|---|
operator== |
Determine whether two time_zone_link objects have the same name . The target name isn't part of the equality check. |
operator<=> |
Compare this time_zone_link against another time_zone_link . The >, >=, <=, <, != operators are synthesized by the compiler. Returns Left.name() <=> Right.name() . |
Header: <chrono>
Time-zone data is only available for Windows 10 version 1903/19H1 and later, and Windows Server 2022 and later.
Namespace: std::chrono
Compiler Option: /std:c++latest
Gets the alternate name for the time zone.
string_view name() const noexcept;
Gets the name of the time_zone
that this time_zone_link
is an alternative name for.
string_view target() const noexcept; // Since C++20
The following example displays the names of each time_zone_link
in the IANA time zone database.
// compile using: /std:c++latest
#include <iostream>
#include <chrono>
using namespace std::chrono;
int main()
{
const auto& my_tzdb = get_tzdb(); // get the IANA time zone database
auto& links = my_tzdb.links; // get the list of time_zone_links from the database
std::for_each(links.begin(), links.end(), // display each time_zone_link name and target
[](auto& l)
{
std::cout << "Name: " << l.name() << "Target" << l.target() << '\n';
});
return 0;
}
Name: ACT Target:Australia/Darwin
Name: AET Target:Australia/Sydney
Name: AGT Target:America/Buenos_Aires
Name: ART Target:Africa/Cairo
Name: AST Target:America/Anchorage
Name: Africa/Asmara Target:Africa/Asmera
Name: Africa/Timbuktu Target:Africa/Bamako
Name: America/Argentina/Buenos_Aires Target:America/Buenos_Aires
Name: America/Argentina/Catamarca Target:America/Catamarca
...
Name: Zulu Target:Etc/UTC