std::chrono::current_zone(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

✨ std::chrono::current_zone ✨

okay bestie, this is the std::chrono::current_zone(3) page from the C++ Standard Libary man pages β€” yes, the header really spells it β€œLibary,” and we’re preserving the source no cap πŸ’€. It’s giving β€œtiny but mighty C++ time zone moment,” and honestly? iconic πŸŽ€


πŸ’– NAME πŸ’–

std::chrono::current_zone β€” literally std::chrono::current_zone, bestie. That’s the whole name. Short, sweet, no notes ✨


🌸 Synopsis 🌸

Defined in header <chrono> β€” yes, the chrono girlies know πŸ•°οΈ

const std::chrono::time_zone* current_zone();  (since C++20)

It’s the convenience function for obtaining your local time zone from the time zone database. Equivalent to std::chrono::get_tzdb().current_zone(). Lowkey a shortcut, highkey useful πŸ’…


🫢 Exceptions 🫢

bestie, listen: std::runtime_error if this is the first reference to the time zone database and the time zone database cannot be initialized. That’s the β€œthe vibe check failed” case 😭

🧚 Notes 🧚

A call to this function that is the first reference to the time zone database will cause it to be initialized. So yeah, first touch = init time. Not me accidentally waking up the whole database on the first call πŸ™ˆβœ¨


🌈 Example 🌈

       // Run this code

        #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 πŸ‘‘

  • current_zone β€” return the local time zone (public member function of std::chrono::tzdb)
  • get_tzdb
  • get_tzdb_list β€” accesses and controls the global time zone database information
  • reload_tzdb β€” (function)
  • remote_version β€” (C++20)

mwah πŸ’‹ this page was served from http://cppreference.com, version/date 2024.06.10, and its title is std::chrono::current_zone(3). Now go forth and get your local time zone, bestie β€” periodt πŸ’–πŸ¦‹βœ¨

πŸ“¦ where this page comes from