最終更新日時(UTC):
が更新

履歴 編集

class template
<chrono>

std::chrono::time_point(C++11)

namespace std {
namespace chrono {
  template <class Clock, class Duration = typename Clock::duration>
  class time_point;
}}

概要

time_pointは、時間軸上の一点を表現するクラスである。

エポックと呼ばれる、起点となる時間からの経過時間によって時間軸上の一点を表す。

エポックはテンプレートパラメータ Clock によって定められ、異なる Clock 同士での演算はできない。

メンバ関数

構築/コピー/破棄

名前 説明 対応バージョン
(constructor) コンストラクタ C++11

観測

名前 説明 対応バージョン
time_since_epoch エポックからの経過時間を取得する C++11

算術演算

名前 説明 対応バージョン
operator+= 時間を進める C++11
operator-= 時間を戻す C++11

特別な値

名前 説明 対応バージョン
min 最小値 C++11
max 最大値 C++11

メンバ型

名前 説明 対応バージョン
clock 時計型 Clock C++11
duration 時間間隔の型 Duration C++11
rep 時間間隔の数値型 Duration::rep C++11
period 時間の周期を表す型 Duration::period C++11

非メンバ関数

丸め演算

名前 説明 対応バージョン
time_point_cast ゼロ方向への丸め C++11
floor 負の無限大方向への丸め C++17
ceil 正の無限大方向への丸め C++17
round 偶数方向への丸め C++17

算術演算

名前 説明 対応バージョン
operator+ 加算 C++11
operator- 減算 C++11

比較演算

名前 説明 対応バージョン
operator== 等値比較を行う C++11
operator!= 非等値比較を行う C++11
operator<=> 三方比較を行う C++20
operator< 左辺が右辺より小さいか比較を行う C++11
operator<= 左辺が右辺以下かの比較を行う C++11
operator> 左辺が右辺より大きいか比較を行う C++11
operator>= 左辺が右辺以上かの比較を行う C++11

common_type特殊化

名前 説明 対応バージョン
common_type 異なるtime_point間の共通の型を求める C++11

#include <iostream>
#include <chrono>
#include <ctime>
#include <iomanip>

using std::chrono::system_clock;

int main() {
  // 現在日時を取得
  system_clock::time_point p = system_clock::now();

  // 出力
  std::time_t t = system_clock::to_time_t(p);
  const std::tm* lt = std::localtime(&t);
  std::cout << std::put_time(lt, "%c") << std::endl;
}

出力例

Thu Jul 18 13:46:26 2013

バージョン

言語

  • C++11

処理系

参照