Namespaces
Variants
Actions

std::chrono::current_zone

From cppreference.com
< cpp‎ | chrono
 
C++
 
Date and time library
Time point
(C++11)
(C++20)
Duration
(C++11)
Clocks
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
Time of day
(C++20)(C++20)
(C++20)(C++20)
(C++20)
Calendar
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)
chrono I/O
(C++20)

Time zone
(C++20)
(C++20)
(C++20)
(C++20)
current_zone
(C++20)
(C++20)
(C++20)
(C++20)
C-style date and time
 
Defined in header <chrono>
const std::chrono::time_zone* current_zone();
(since C++20)

Convenience function for obtaining local time zone from the time zone database. Equivalent to std::chrono::get_tzdb().current_zone().

Contents

[edit] Exceptions

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

[edit] Notes

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

[edit] Example

#include <chrono>
#include <iostream>
 
int main()
{
    try
    {
        const std::chrono::zoned_time cur_time
        {
            std::chrono::current_zone(), / may throw
            std::chrono::system_clock::now()
        };
        std::cout << cur_time << '\n';
    }
    catch(const std::runtime_error& ex)
    {
        std::cerr << ex.what() << '\n';        
    }
}

Possible output:

2021-09-13 19:46:42.249182012 MAGT

[edit] See also

return the local time zone
(public member function of std::chrono::tzdb) [edit]
accesses and controls the global time zone database information
(function) [edit]

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant