std::chrono::time_point::time_point
STD::时间::时间[医]要点::时间[医]点
| (1) | |
---|---|---|
time_point( | (since C++11) (until C++14) | |
constexpr time_point( | (since C++14) | |
| (2) | |
explicit time_point( const duration& d | (since C++11) (until C++14) | |
constexpr explicit time_point( const duration& d | (since C++14) | |
| (3) | |
template< class Duration2 > time_point( const time_point<Clock,Duration2>& t | (since C++11) (until C++14) | |
template< class Duration2 > constexpr time_point( const time_point<Clock,Duration2>& t | (since C++14) |
构造一个新的time_point
来自几个可选数据源之一。
1%29默认构造函数,创建time_point
价值为Clock
%27S时代
2%29构造一个time_point
在Clock
%27S时代加d
...
3%29构造一个time_point
通过转换t
到duration
.此构造函数仅参与重载解析,如果Duration2
隐式可转换为duration
...
参数
d | - | a duration to copy from |
---|---|---|
t | - | a time_point to convert from |
例
二次
#include <chrono>
#include <iostream>
using Clock = std::chrono::high_resolution_clock;
using TimePoint = std::chrono::time_point<Clock>;
void print_ms(const TimePoint& point)
{
using Ms = std::chrono::milliseconds;
const Clock::duration since_epoch = point.time_since_epoch(
std::cout << std::chrono::duration_cast<Ms>(since_epoch).count() << " ms\n";
}
int main()
{
const TimePoint default_value = TimePoint( // (1)
print_ms(default_value // 0 ms
const Clock::duration duration_4_seconds = std::chrono::seconds(4
const TimePoint time_point_4_seconds(duration_4_seconds // (2)
// 4 seconds from start of epoch
print_ms(time_point_4_seconds // 4000 ms
const TimePoint time_point_now = Clock::now( // (3)
print_ms(time_point_now // 43098276 ms
}
二次
可能的产出:
二次
0 ms
4000 ms
43098276 ms
二次
另见
(constructor) | constructs new duration (public member function of std::chrono::duration) |
---|---|
duration_cast | converts a duration to another, with a different tick interval (function template) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。