std::chrono::time_point<Clock,Duration>::time_point
来自cppreference.com
< cpp | chrono | time point
(1) | ||
time_point(); |
(C++11 起) (C++14 前) |
|
constexpr time_point(); |
(C++14 起) | |
(2) | ||
explicit time_point( const duration& d ); |
(C++11 起) (C++14 前) |
|
constexpr explicit time_point( const duration& d ); |
(C++14 起) | |
(3) | ||
template< class Duration2 > time_point( const time_point<Clock,Duration2>& t ); |
(C++11 起) (C++14 前) |
|
template< class Duration2 > constexpr time_point( const time_point<Clock,Duration2>& t ); |
(C++14 起) | |
从数个可选数据源之一构造新的 time_point
。
2) 构造位于
Clock
的纪元加上 d
的 time_point
。3) 通过转换
t
为 duration
构造 time_point
。此构造函数仅若 Duration2
可隐式转换为 duration
才参与重载决议。参数
d | - | 复制来源的 duration
|
t | - | 转换来源的 time_point
|
示例
运行此代码
#include <chrono> #include <iostream> using Clock = std::chrono::high_resolution_clock; using TimePoint = std::chrono::time_point<Clock>; void print_ms(const TimePoint& point) { using Ms = std::chrono::milliseconds; const Clock::duration since_epoch = point.time_since_epoch(); std::cout << std::chrono::duration_cast<Ms>(since_epoch).count() << " ms\n"; } int main() { const TimePoint default_value = TimePoint(); // (1) print_ms(default_value); // 0 ms const Clock::duration duration_4_seconds = std::chrono::seconds(4); const TimePoint time_point_4_seconds(duration_4_seconds); // (2) // 从纪元开始 4 秒 print_ms(time_point_4_seconds); // 4000 ms const TimePoint time_point_now = Clock::now(); // (3) print_ms(time_point_now); // 43098276 ms }
可能的输出:
0 ms 4000 ms 43098276 ms
参阅
构造新 duration ( std::chrono::duration<Rep,Period> 的公开成员函数) | |
转换时长到另一个拥有不同嘀嗒间隔的时长 (函数模板) |