std::chrono::time_zone:: to_local
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
|
time_zone::to_local
|
||||
| Nonmember functions | ||||
|
template
<
class
Duration
>
auto
to_local
(
const
std::
chrono
::
sys_time
<
Duration
>
&
tp
)
const
|
(seit C++20) | |
Konvertiert den
sys_time
tp
in die entsprechende
local_time
in dieser
Zeitzone
.
Inhaltsverzeichnis |
Parameter
| tp | - | ein umzuwandelnder Zeitpunkt |
Rückgabewert
Das local_time assoziierte mit tp und dieser Zeitzone.
Hinweise
Die Genauigkeit des Ergebnisses beträgt mindestens std::chrono::seconds und wird feiner sein, wenn das Argument eine höhere Präzision aufweist.
Beispiel
#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'; } }
Mögliche Ausgabe:
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