std::chrono::time_point
From Cppreference
C++ Standard Library | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Utilities library | ||||||||||||||||||||||||||||||||||||||||
Date and time utilities | ||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||
Defined in header <chrono>
|
||
Defined in namespace std::chrono
| ||
template< class Clock, class Duration = typename Clock::duration >
class time_point; |
(C++11 feature) | |
Class template std::chrono::time_point represents a point in time. It is implemented as if storing the value of type Duration indicating the time interval from the start of the Clock's epoch.
Contents |
[edit] 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, an std::ratio type representing the tick period of the duration |
[edit] Member functions
|
constructs a new time point (public member function) |
|
|
returns the time point as duration since the start of its clock (public member function) |
|
|
increases the time point by given duration (public member function) |
|
|
decreases the time point by given duration (public member function) |
|
|
returns the time point corresponding to the largest duration (public member function) |
|
|
returns the time point corresponding to the smallest duration (public member function) |
[edit] Non-member functions
|
specializes the std::common_type trait (class template specialization) |
|
|
adds a duration to a time_point (public member function) |
|
|
subtracts a duration from a time_point (public member function) |
|
|
compares two time points (public member function) |
|
|
converts a time point to another time point on the same clock, with a different duration (public member function) |
[edit] Example
This example prints the current time minus 24 hours
#include <iostream> #include <iomanip> #include <ctime> #include <chrono> int main() { std::chrono::time_point<std::chrono::system_clock> 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 << "One day ago, the time was " << std::put_time(std::localtime(&now_c), "%F %T") << '\n'; }
Output:
One day ago, the time was 2011-10-25 12:00:08
[edit] See also
|
a time interval (class template) |