gps_clock

全球定位系统 (GPS) 时间的时钟。

语法

class gps_clock; // C++20

备注

此时钟测量自 1980 年 1 月 6 日 00:00:00 UTC 星期日起的时间。

此时钟不考虑闰秒。 每当闰秒添加到 UTC 时间,UTC 将比 GPS 时间再落后一秒。

GPS 时间落后 TAI 时间 19 秒,因为 1972 年 TAI 时间添加了 10 秒,以计入累积到该点的闰秒,1970 年至 1980 年间 TAI 时间又另外添加了 9 个闰秒。

成员

名称 描述
from_utc 静态。 将 utc_time 转换为 gps_time
now 静态。 返回 GPS 当前时间。
to_utc 静态。 将 gps_time 转换为 utc_time

非成员

“属性” 描述
from_stream 使用指定格式从给定流分析 gps_time
operator<< gps_time 输出到给定流。

便利类型别名

名称 描述
gps_clock::duration 在 Microsoft 的实现中,它是 duration<long long, ratio<1, 10'000'000> 的同义词。 它表示以 100 纳秒为单位测量的持续时间。
gps_clock::period 在 Microsoft 的实现中,它是 ratio<1, 10'000'000> 的同义词。 它以秒的分数(100 纳秒)为单位表示持续时间中每个时钟计时周期的时间。
gps_clock::rep 用于表示此时钟的 gps_clock::duration 中的整数单位的类型 (long long) 的同义词。
gps_clock::time_point time_point<gps_clock> 的同义词。 用于表示此时钟的 time_point

相关

名称 描述
gps_time template <class Duration> using gps_time = time_point<gps_clock, Duration> 的同义词。 用于表示 gps_clocktime_point。 指定 Duration。 在 std::chrono 中定义
gps_seconds using gps_seconds = gps_time<seconds>; 的同义词。秒数,由与 gps_clock 关联的 time_point 表示。 在 std::chrono 中定义

公共常量

“属性” 描述
gps_clock::is_steady 常量 指示时钟类型是否为稳定。 其值为 false

要求

标头: <chrono> (自C++20以来)

命名空间std::chrono

编译器选项: /std:c++latest

from_utc

utc_time 转换为 gps_time 的静态方法。

template<class Duration>
static gps_time<common_type_t<Duration, seconds>>
from_utc(const utc_time<Duration>& t) noexcept;

参数

t
要转换的 utc_time

返回值

gps_time设置为与该utc_timet时间点相同的时间点。 它计算为 gps_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} - 315964809s,其中 315964809s == sys_days{1980y/January/Sunday[1]} - sys_days{1970y/January/1} + 9s。 它是 utc_clock 纪元与 gps_clock 纪元之间的秒数。

to_utc

gps_time 转换为 utc_time 的静态方法。

template<class Duration>
static utc_time<common_type_t<Duration, seconds>>
to_utc(const gps_time<Duration>& t) noexcept;

参数

t
要转换的 gps_time

返回值

utc_time 设置为与 gps_time 时间点相同的时间点。 它计算为 gps_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} + 315964809s,其中 315964809s == sys_days{1980y/January/Sunday[1]} - sys_days{1970y/January/1} + 9s。 它是 utc_clockgps_clock 纪元之间的秒数。

is_steady

指定时钟类型是否为稳定的静态值。 在 Microsoft 的实现中,is_steady_constant 始终为 false。 由于 gps_clock 不稳定,因此不能可靠地使用此时钟获取事件之前的时间、事件之后的时间,以及使它们相减以获取事件的持续时间,因为在该时间期间时钟可能会调整。

static const bool is_steady = system_clock::is_steady; // system_clock::is_steady equals false

now

返回当前 GPS 时间的静态方法。

static time_point now() noexcept;

返回值

表示当前对象的 time_point 对象。 返回的时间点实际为 from_utc(utc_clock::now())

另请参阅

<chrono>
file_clock class
high_resolution_clock
local_t 结构
steady_clock 结构
system_clock 结构
tai_clock
头文件引用