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 的公开成员函数) | |
访问和控制全局时区数据库信息 (函数) |