std::chrono::current_zone
来自 cppreference.cn
定义于头文件 <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(), // may throw 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 的公共成员函数) | |
访问和控制全局时区数据库信息 (函数) |