|
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
time_zone::to_local | ||||
| Nonmember functions | ||||
template<class Duration> auto to_local(conststd::chrono::sys_time<Duration>& tp)const | (since C++20) | |
Converts thesys_timetp to the correspondinglocal_time in thistime zone.
Contents |
| tp | - | a time point to be converted |
Thelocal_time associated withtp and this time zone.
The precision of the result is at leaststd::chrono::seconds, and will be finer if the argument has finer precision.
#include <chrono>#include <iostream> int main(){constauto some_zone_name{"Australia/Sydney"};constauto 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(conststd::runtime_error& ex){std::cout<< ex.what()<<'\n';}}
Possible output:
Current time UTC is: 2025-02-10 13:38:13.233872158Current time local is: 2025-02-10 16:38:13.233872158Current time Australia/Sydney is: 2025-02-11 00:38:13.233872158