标签:float 休眠 ddd 系统时间 dde ant uil targe reboot
time_point定义在<chrono>
文件中,用来表示时间点。
关键代码摘录如下(格式有调整):
注:time_point要求其_Clock模板参数必须满足Clock的要求。
time_point的实现很简单,使用Duration类型的成员变量存储时间,make sense!
仔细想想,时间点不就是从0时刻开始经过一定时间间隔的某一个时刻吗?
Clock
参数如何使用?std::chrono提供的clock有system_clock, steady_clock,high_resolution_clock
Class std::chrono::system_clock represents the system-wide real time wall clock.
It may not be monotonic: on most systems, the system time can be adjusted at any moment. It is the only C++ clock that has the ability to map its time points to C-style time, and, therefore, to be displayed.
std::chrono::system_clock meets the requirements of TrivialClock.
The epoch of system_clock is unspecified, but most implementations use Unix Time (i.e., time since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970, not counting leap seconds).
(until C++20)
system_clock measures Unix Time (i.e., time since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970, not counting leap seconds).
(since C++20)
相较于steady_clock,system_clock是不稳定的,可能在两次调用之间,系统时间已经被修改了。
Class std::chrono::steady_clock represents a monotonic clock. The time points of this clock cannot decrease as physical time moves forward. This clock is not related to wall clock time (for example, it can be time since last reboot), and is most suitable for measuring intervals.
std::chrono::steady_clock meets the requirements of TrivialClock.
steady_clock正如其名,是稳定的。适合用来测量时间间隔。
Class std::chrono::high_resolution_clock represents the clock with the smallest tick period provided by the implementation. It may be an alias of std::chrono::system_clock or std::chrono::steady_clock, or a third, independent clock.
std::chrono::high_resolution_clock meets the requirements of TrivialClock.
注:在vs中,high_resolution_clock是steady_clock的typedef。
例1. 休眠10秒钟
例2. 计时代码
一个简单的计时代码,展示了std::chrono::high_resolution_clock和std::chrono::duration的用法。
std::chrono::system_clock::time_point
定义:
[原]C++新标准之std::chrono::time_point
标签:float 休眠 ddd 系统时间 dde ant uil targe reboot
原文地址:https://www.cnblogs.com/bianchengnan/p/9478806.html