在线文档教程
C++
应用 | Utilities

std::chrono::time_point

STD::时间::时间[医]点

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

类模板std::chrono::time_point表示时间点。它的实现就好像它存储类型的值一样。Duration的起始时间间隔。Clock%27S时代

成员类型

Member typeDefinition
clockClock, the clock on which this time point is measured
durationDuration, a std::chrono::duration type used to measure the time since epoch
repRep, an arithmetic type representing the number of ticks of the duration
periodPeriod, a std::ratio type representing the tick period of the duration

成员函数

(constructor)constructs a new time point (public member function)
time_since_epochreturns the time point as duration since the start of its clock (public member function)
operator+=operator-=modifies the time point by the given duration (public member function)
min staticreturns the time point corresponding to the smallest duration (public static member function)
max staticreturns the time point corresponding to the largest duration (public static member function)

非会员职能

std::common_typespecializes the std::common_type trait (class template specialization)
operator+operator-modifies the time point by the given duration (function template)
operator==operator!=operator<operator<=operator>operator>=compares two time points (function template)
time_point_castconverts a time point to another time point on the same clock, with a different duration (function template)
floor(std::chrono::time_point) (C++17)converts a time_point to another, rounding down (function template)
ceil(std::chrono::time_point) (C++17)converts a time_point to another, rounding up (function template)
round(std::chrono::time_point) (C++17)converts a time_point to another, rounding to nearest, ties to even (function template)

二次

#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"; }

二次

可能的产出:

二次

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

二次

另见

duration (C++11)a time interval (class template)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/crono/time[医]点