Convert chrono duration to time_point

9.7k views Asked by At

How can I convert a chrono duration to a time_point, which is later than clock's epoch with the given duration? I tried to find epoch time in chrono clock without success.

1

There are 1 answers

0
Howard Hinnant On BEST ANSWER

From the synopsis in 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

This can be used (for example) like:

using namespace std::chrono;
system_clock::time_point tp{30min}; // Needs C++14 for the literal

Though the system_clock::time_point is not specified in the standard, in practice this creates a time_point referring to 1970-01-01 00:30:00 UTC.