std::chrono::time_point - cppreference.com
提供: cppreference.com
<tbody> </tbody>
|
|
(C++11以上) | |
クラステンプレート std::chrono::time_point は時のある一点を表します。 Clock のエポック開始点からの経過時間を表す Duration 型の値を格納するかのように実装されます。
Clock は std::chrono::local_t であるか (C++20以上) Clock の要件を満たさなければなりません。
メンバ型
| メンバ型 | 定義 |
clock
|
Clock、この時点を測る時計
|
duration
|
Duration、エポックからの時間を測るために使用される std::chrono::duration 型
|
rep
|
Rep、時間の刻みの数を表す算術型
|
period
|
Period、時間の刻み幅を表す std::ratio 型
|
メンバ関数
| 新しい time point を構築します (パブリックメンバ関数) [edit] | |
| この time point を時計の開始点からの経過時間として返します (パブリックメンバ関数) [edit] | |
| time point を指定された時間で変更します (パブリックメンバ関数) [edit] | |
| duration をインクリメントまたはデクリメントします (パブリックメンバ関数) [edit] | |
[静的] |
最も小さな時間に対応する time point を返します (パブリック静的メンバ関数) [edit] |
[静的] |
最も大きな時間に対応する time point を返します (パブリック静的メンバ関数) [edit] |
非メンバ関数
| time point に対する加算および減算を行います (関数テンプレート) [edit] | |
| 2つの time point を比較します (関数テンプレート) [edit] | |
| time point を同じ時計の異なる時間単位の time point に変換します (関数テンプレート) [edit] | |
| time_point を別の time_point に切り捨て変換します (関数テンプレート) [edit] | |
| time_point を別の time_point に切り上げ変換します (関数テンプレート) [edit] | |
| time_point を別の time_point の最も近い値に変換します (関数テンプレート) [edit] |
ヘルパークラス
例
#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 t_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(&t_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.