std::chrono:: current_zone
From cppreference.net
C++
Date and time library
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定义于头文件
<chrono>
|
||
|
const
std::
chrono
::
time_zone
*
current_zone
(
)
;
|
(C++20 起) | |
用于从 时区数据库 获取本地时区的便捷函数。等价于 std:: chrono :: get_tzdb ( ) . current_zone ( ) 。
目录 |
异常
std::runtime_error 如果这是对时区数据库的首次引用且时区数据库无法初始化。
注释
对此函数的首次调用若为时区数据库的首次引用,将触发其初始化过程。
示例
运行此代码
#include <chrono> #include <iostream> int main() { try { const std::chrono::zoned_time cur_time { std::chrono::current_zone(), // 可能抛出异常 std::chrono::system_clock::now() }; std::cout << cur_time << '\n'; } catch(const std::runtime_error& ex) { std::cerr << ex.what() << '\n'; } }
可能的输出:
2021-09-13 19:46:42.249182012 MAGT
参见
|
返回本地时区
(
std::chrono::tzdb
的公开成员函数)
|
|
|
访问并控制全局时区数据库信息
(函数) |