std::chrono::time_zone::to_local
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Date and time library
(C++11)
(C++20)
(C++20)
(C++11)
(C++11)
(C++11)
(C++20)
(C++20)
(C++20)
(C++11)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
std::chrono::time_zone
Member functions
time_zone::to_local
Nonmember functions
template< class Duration >
(since C++20)
auto to_local( const std::chrono::sys_time <Duration>& tp ) const
Converts the sys_time
tp to the corresponding local_time
in this time zone.
Contents
[edit] Parameters
tp
-
a time point to be converted
[edit] Return value
The local_time associated with tp and this time zone.
[edit] Notes
The precision of the result is at least std::chrono::seconds , and will be finer if the argument has finer precision.
[edit] Example
Run this code
#include <chrono> #include <iostream> int main() { const auto some_zone_name{"Australia/Sydney"}; const auto time_pt_utc{std::chrono::system_clock::now ()}; std::cout << "Current time UTC is:\t\t " << time_pt_utc << '\n'; try { std::cout << "Current time local is:\t\t " << std::chrono::current_zone ()-> // may throw to_local(time_pt_utc) << '\n' << "Current time " << some_zone_name << " is:\t " << std::chrono::locate_zone (some_zone_name)-> // may throw to_local(time_pt_utc) << '\n'; } catch(const std::runtime_error & ex) { std::cout << ex.what() << '\n'; } }
Possible output:
Current time UTC is: 2025年02月10日 13:38:13.233872158 Current time local is: 2025年02月10日 16:38:13.233872158 Current time Australia/Sydney is: 2025年02月11日 00:38:13.233872158