Skip to content

Latest commit

 

History

History
88 lines (67 loc) · 2.32 KB

time_point_cast.md

File metadata and controls

88 lines (67 loc) · 2.32 KB

time_point_cast

  • chrono[meta header]
  • std::chrono[meta namespace]
  • function template[meta id-type]
  • cpp11[meta cpp]
namespace std {
namespace chrono {
  template <class ToDuration, class Clock, class Duration>
  time_point<Clock, ToDuration>
    time_point_cast(const time_point<Clock, Duration>& t); // C++11

  template <class ToDuration, class Clock, class Duration>
  constexpr time_point<Clock, ToDuration>
    time_point_cast(const time_point<Clock, Duration>& t); // C++14
}}
  • time_point[link /reference/chrono/time_point.md]

概要

分解能の低いduration型を内部表現として持つtime_pointへ変換する。

その際の丸めは、ゼロ方向への丸め (切り捨て、truncate) が行われる。

戻り値

time_point<Clock, ToDuration>(duration_cast<ToDuration>(t.time_since_epoch()));
  • time_point[link /reference/chrono/time_point.md]
  • duration_cast[link /reference/chrono/duration_cast.md]
  • time_since_epoch[link /reference/chrono/time_point/time_since_epoch.md]

#include <iostream>
#include <chrono>

using namespace std::chrono;

int main()
{
  using MTimePoint = time_point<system_clock, milliseconds>;
  using STimePoint = time_point<system_clock, seconds>;

  MTimePoint mp(milliseconds(1100));

//STimePoint sp = mp; // error! 変換できない
  STimePoint sp = time_point_cast<seconds>(mp); // OK

  std::cout << sp.time_since_epoch().count() << std::endl;
}
  • time_point[link time_point.md]
  • system_clock[link system_clock.md]
  • time_point_cast[color ff0000]
  • milliseconds[link milliseconds.md]
  • seconds[link seconds.md]
  • time_since_epoch()[link time_point/time_since_epoch.md]
  • count()[link duration/count.md]

出力

1

バージョン

言語

  • C++11

処理系

関連項目

名前 説明
floor 負の無限大方向への丸め
ceil 正の無限大方向への丸め
round 偶数方向への丸め

参照