std::chrono::time_point (3) - Linux Man Pages

std::chrono::time_point: std::chrono::time_point


std::chrono::time_point - std::chrono::time_point


Defined in header <chrono>
class Clock, (since C++11)
class Duration = typename Clock::duration
> class time_point;

Class template std::chrono::time_point represents a point in time. It is implemented as if it stores a value of type Duration indicating the time interval from the start of the Clock's epoch.
Clock must meet the requirements for Clock
or be std::chrono::local_t
(since C++20).

Member types

Member type Definition
clock Clock, the clock on which this time point is measured
duration Duration, a std::chrono::duration type used to measure the time since epoch
rep Rep, an arithmetic type representing the number of ticks of the duration
period Period, a std::ratio type representing the tick period of the duration

Member functions

                 constructs a new time point
constructor (public member function)
                 returns the time point as duration since the start of its clock
time_since_epoch (public member function)
                 modifies the time point by the given duration
operator+= (public member function)

operator++(int) increments or decrements the duration
operator-- (public member function)


min returns the time point corresponding to the smallest duration
                 (public static member function)

max returns the time point corresponding to the largest duration
                 (public static member function)

Non-member functions

                                          specializes the std::common_type trait
std::common_type<std::chrono::time_point> (class template specialization)
                                          performs add and subtract operations involving a time point
operator+ (function template)

operator!= compares two time points
operator< (function template)
                                          converts a time point to another time point on the same clock, with a different duration
time_point_cast (function template)

floor(std::chrono::time_point) converts a time_point to another, rounding down
                                          (function template)

ceil(std::chrono::time_point) converts a time_point to another, rounding up
                                          (function template)

round(std::chrono::time_point) converts a time_point to another, rounding to nearest, ties to even
                                          (function template)


// Run this code

  #include <iostream>
  #include <iomanip>
  #include <ctime>
  #include <chrono>

  int main()
      std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
      std::time_t now_c = std::chrono::system_clock::to_time_t(now - std::chrono::hours(24));
      std::cout << "24 hours ago, the time was "
                << std::put_time(std::localtime(&now_c), "%F %T") << '\n';

      std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
      std::cout << "Hello World\n";
      std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
      std::cout << "Printing took "
                << std::chrono::duration_cast<std::chrono::microseconds>(end - start).count()
                << "us.\n";

Possible output:

  24 hours ago, the time was 2011-10-25 12:00:08
  Hello World
  Printing took 84us.

See also

duration a time interval
         (class template)