Namespaces
Variants

std::chrono::time_zone:: to_sys

From cppreference.net
template < class Duration >

auto to_sys ( const std:: chrono :: local_time < Duration > & tp ) const

- > std:: chrono :: sys_time < std:: common_type_t < Duration, std:: chrono :: seconds >> ;
(1) (自 C++20 起)
template < class Duration >

auto to_sys ( const std:: chrono :: local_time < Duration > & tp, std:: chrono :: choose z ) const

- > std:: chrono :: sys_time < std:: common_type_t < Duration, std:: chrono :: seconds >> ;
(2) (自 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::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

示例