名前空間
変種
操作

std::chrono::time_point

提供: cppreference.com
< cpp‎ | chrono
 
 
ユーティリティライブラリ
汎用ユーティリティ
日付と時間
関数オブジェクト
書式化ライブラリ (C++20)
(C++11)
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)
スワップと型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
一般的な語彙の型
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

初等文字列変換
(C++17)
(C++17)
 
日付と時間のユーティリティ
(C++11)
time_point
(C++11)
時刻
(C++20)



(C++20)(C++20)(C++20)(C++20)
時計
(C++20)
                                             
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
カレンダー
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
タイムゾーン
(C++20)
(C++20)
(C++20)
(C++20)
C スタイルの日付と時間
 
 
ヘッダ <chrono> で定義
template<

    class Clock,
    class Duration = typename Clock::duration

> class time_point;
(C++11以上)

クラステンプレート std::chrono::time_point は時のある一点を表します。 Clock のエポック開始点からの経過時間を表す Duration 型の値を格納するかのように実装されます。

Clockstd::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]

[編集] ヘルパークラス

std::common_type 特性の特殊化
(クラステンプレートの特殊化) [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.

[編集] 関連項目

(C++11)
時の間隔
(クラステンプレート) [edit]