Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The latest version of this topic can be found at <chrono>.
Include the standard header <chrono> to define classes and functions that represent and manipulate time durations and time instants.
(Visual Studio 2015:) The implementation of steady_clock has changed to meet the C++ Standard requirements for steadiness and monotonicity. steady_clock is now based on QueryPerformanceCounter() and high_resolution_clock is now a typedef for steady_clock. As a result, in Visual C++ steady_clock::time_point is now a typedef for chrono::time_point<steady_clock>; however, this is not necessarily the case for other implementations.
Syntax
#include <chrono>  
Literals
Literals in the <chrono> header are members of the literals::chrono_literals inline namespace. For more information, see chrono literals.
| operator "" h(unsigned long long Val) operator "" h(long double Val) | Specifies that the value represents hours. | 
| operator "" min(unsigned long long Val) operator "" min(long double Val) | Specifies that the value represents minutes. | 
| operator "" s(unsigned long long Val)operator "" s(long double Val) | Specifies that the value represents seconds. | 
| operator "" ms(unsigned long long Val)operator "" ms(long double Val) | Specifies that the value represents milliseconds. | 
| operator "" us(unsigned long long Val)operator "" us(long double Val) | Specifies that the value represents microseconds. | 
| operator "" ns(unsigned long long Val)operator "" ns(long double Val) | Specifies that the value represents nanoseconds. | 
Classes
| Name | Description | 
|---|---|
| duration Class | Describes a type that holds a time interval. | 
| time_point Class | Describes a type that represents a point in time. | 
Structs
| Name | Description | 
|---|---|
| common_type Structure | Describes specializations of template class common_type for instantiations of durationandtime_point. | 
| duration_values Structure | Provides specific values for the durationtemplate parameterRep. | 
| steady_clock struct | Represents a steadyclock. | 
| system_clock Structure | Represents a clock type that is based on the real-time clock of the system. | 
| treat_as_floating_point Structure | Specifies whether a type can be treated as a floating-point type. | 
Functions
| Name | Description | 
|---|---|
| duration_cast Function | Casts a durationobject to a specified type. | 
| time_point_cast Function | Casts a time_pointobject to a specified type. | 
Operators
| Name | Description | 
|---|---|
| operator- | Operator for subtraction or negation of durationandtime_pointobjects. | 
| operator!= | Inequality operator that is used with durationortime_pointobjects. | 
| operator modulo | Operator for modulo operations on durationobjects. | 
| operator* | Multiplication operator for durationobjects. | 
| operator/ | Division operator for durationobjects. | 
| operator+ | Adds durationandtime_pointobjects. | 
| operator< | Determines whether one durationortime_pointobject is less than anotherdurationortime_pointobject. | 
| operator<= | Determines whether one durationortime_pointobject is less than or equal to anotherdurationortime_pointobject. | 
| operator== | Determines whether two durationobjects represent time intervals that have the same length, or whether twotime_pointobjects represent the same point in time. | 
| operator> | Determines whether one durationortime_pointobject is greater than anotherdurationortime_pointobject. | 
| operator>= | Determines whether one durationortime_pointobject is greater than or equal to anotherdurationortime_pointobject. | 
Predefined Duration Types
For more information about ratio types that are used in the following typedefs, see <ratio>.
| Typedef | Description | 
|---|---|
| typedef duration<long long, nano> nanoseconds; | Synonym for a durationtype that has a tick period of one nanosecond. | 
| typedef duration<long long, micro> microseconds; | Synonym for a durationtype that has a tick period of one microsecond. | 
| typedef duration<long long, milli> milliseconds; | Synonym for a durationtype that has a tick period of one millisecond. | 
| typedef duration<long long> seconds; | Synonym for a durationtype that has a tick period of one second. | 
| typedef duration<int, ratio<60> > minutes; | Synonym for a durationtype that has a tick period of one minute. | 
| typedef duration<int, ratio<3600> > hours; | Synonym for a durationtype that has a tick period of one hour. | 
Literals
(C++11)The <chrono> header defines the following user-defined literals that you can use for greater convenience, type-safety and maintainability of your code. These literals are defined in the literals::chrono_literals inline namespace and are in scope when std::chrono is in scope.
| Literal | Description | 
|---|---|
| chrono::hours operator "" h(unsigned long long Val) | Specifies hours as an integral value. | 
| chrono::duration<double, ratio<3600> > operator "" h(long double Val) | Specifies hours as a floating-point value. | 
| chrono::minutes (operator "" min)(unsigned long long Val) | Specifies minutes as an integral value. | 
| chrono::duration<double, ratio<60> > (operator "" min)( long double Val) | Specifies minutes as a floating-point value. | 
| chrono::seconds operator "" s(unsigned long long Val) | Specifies minutes as an integral value. | 
| chrono::duration<double> operator "" s(long double Val) | Specifies seconds as a floating-point value. | 
| chrono::milliseconds operator "" ms(unsigned long long Val) | Specifies milliseconds as an integral value. | 
| chrono::duration<double, milli> operator "" ms(long double Val) | Specifies milliseconds as a floating-point value. | 
| chrono::microseconds operator "" us(unsigned long long Val) | Specifies microseconds as an integral value. | 
| chrono::duration<double, micro> operator "" us(long double Val) | Specifies microseconds as a floating-point value. | 
| chrono::nanoseconds operator "" ns(unsigned long long Val) | Specifies nanoseconds as an integral value. | 
| chrono::duration<double, nano> operator "" ns(long double Val) | Specifies nanoseconds as a floating-point value. |