将计时持续时间转换为time_point

sim*_*mon 2 c++11 c++-chrono

如何将计时持续时间转换为time_point,这比给定持续时间的clock's epoch晚?我试图在计时时钟中找到纪元时间而没有成功.

How*_*ant 5

摘自20.12.6 [time.point]中的概要:

template <class Clock, class Duration = typename Clock::duration>
class time_point
{
public:
    constexpr explicit time_point(const duration& d);  // same as time_point() + d
Run Code Online (Sandbox Code Playgroud)

这可以用于(例如)像:

using namespace std::chrono;
system_clock::time_point tp{30min}; // Needs C++14 for the literal
Run Code Online (Sandbox Code Playgroud)

虽然标准中未指定system_clock :: time_point,但实际上这会创建一个time_point引用1970-01-01 00:30:00 UTC.