std::chrono::system_clock::to_time_t
From cppreference.com
< cpp | chrono | system clock
| static std::time_t to_time_t( const time_point& t ) noexcept; |
(C++11以降) | |
t を std::time_t 型に変換します。
std::time_t の精度が低い場合、値が丸められるか切り捨てられるかは実装定義です。
目次 |
[編集] パラメータ
| t | - | 変換するシステムクロックの時刻点 |
[編集] 戻り値
t を表す std::time_t 値。
[編集] 例
現在の時刻を2つの方法で std::time_t として取得します。
このコードを実行
#include <chrono> #include <ctime> #include <iostream> #include <thread> using namespace std::chrono_literals; int main() { // The old way std::time_t oldt = std::time({}); std::this_thread::sleep_for(2700ms); // The new way auto const now = std::chrono::system_clock::now(); std::time_t newt = std::chrono::system_clock::to_time_t(now); std::cout << "newt - oldt == " << newt - oldt << " s\n"; }
実行結果の例
newt - oldt == 3 s
[編集] 関連項目
| [static] |
std::time_t をシステムクロックの時刻点に変換します。 (public static member function) |