std::chrono::time_zone::to_sys
来自cppreference.com
| template< class Duration > auto to_sys(const std::chrono::local_time<Duration>& tp) const |
(C++20 起) | |
| template< class Duration > auto to_sys(const std::chrono::local_time<Duration>& tp, std::chrono::choose z) const |
(C++20 起) | |
转换此时区中的 local_time tp 为对应的 sys_time 。
1) 若转换有歧义或
tp 表示不存在的时间则抛出异常。2) 按照
z 的值解决歧义:
- 若 z == std::chrono::choose::earliest ,则返回较早的
sys_time。 - 若 z == std::chrono::choose::latest ,则返回较晚的
sys_time。
若
tp 表示二个 UTC time_point 间不存在的时间,则二个 time_point 将相同,并将返回该 time_point 。返回值
按照此时区规则的 tp 的 UTC 等价版本。
异常
1) 若转换有歧义则抛出 std::chrono::ambiguous_local_time 。若
tp 表示不存在的时间则抛出 std::chrono::nonexistent_local_time 。注意
结果的精度至少为 std::chrono::seconds ,而且若参数有更精细的精度则将更精细。
歧义和不存在的本地时间能作为时区转变(例如夏时令)的结果出现。例如, "2016-03-13 02:30:00" 不存在于 "America/New_York" 时区,而该时区中的 "2016-11-06 01:30:00" 能对应二个 UTC 时间点: 2016-11-06 05:30:00 UTC 和 2016-11-06 06:30:00 UTC 。