std::chrono::current_zone

From cppreference.com
< cpp‎ | chrono
 
 
Utilities library
General utilities
Date and time
Function objects
Formatting library (C++20)
(C++11)
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)(C++20)(C++20)   
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)
Elementary string conversions
(C++17)
(C++17)
 
Date and time utilities
Time point
(C++11)
(C++20)
Duration
(C++11)
Clocks
(C++11)      
(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)

Calendars
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)
Time zones
(C++20)
(C++20)
(C++20)
(C++20)
current_zone
(C++20)
(C++20)
(C++20)
chrono I/O
(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().

Exceptions

std::runtime_error 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() {
    const std::chrono::zoned_time cur_time{ std::chrono::current_zone(),
                                            std::chrono::system_clock::now() };
    std::cout << cur_time << '\n';
}

Possible output:

2021-09-13 19:46:42.249182012 MAGT

See also

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