名前空間
変種
操作

Date and time utilities

提供: cppreference.com
< cpp


 
 
ユーティリティライブラリ
支援を入力します (basic types, RTTI, type traits)
動的なメモリ管理
エラー処理
プログラムユーティリティ
可変個引数関数
日付と時刻
関数オブジェクト
initializer_list(C++11)
bitset
hash(C++11)
関係演算子
Original:
Relational operators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
rel_ops::operator!=
rel_ops::operator>
rel_ops::operator<=
rel_ops::operator>=
ペアとタプル
Original:
Pairs and tuples
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
pair
tuple(C++11)
piecewise_construct_t(C++11)
piecewise_construct(C++11)
フォワード、スワップ、および移動
Original:
Swap, forward and move
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
swap
forward(C++11)
move(C++11)
move_if_noexcept(C++11)
declval(C++11)
 
日付と時間のユーティリティ
 
C + +の時間操作の2つのタイプのサポートが含まれています
Original:
C++ includes support for two types of time manipulation:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • chronoライブラリ、種々の精度で時間を追跡するタイプの柔軟なコレクション(例えばstd::chrono::time_point).
    Original:
    The chrono library, a flexible collection of types that track time with varying degrees of precision (e.g. std::chrono::time_point).
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • C形式の日付と時刻ライブラリ(例えばstd::time
    Original:
    C-style date and time library (e.g. std::time)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

目次

[編集] chrono library

chronoライブラリは、主に3つのタイプ(持続時間、時計、タイムポイント)だけでなく、ユーティリティ機能と共通のtypedefを定義しています.
Original:
The chrono library defines three main types (durations, clocks, and time points) as well as utility functions and common typedefs.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] Duration

duration は、単位時間で刻まれるいくつかのtickによって構成される間隔で定義されます。例えば、 "42秒"は、1秒刻みの42tickによって構成される間隔と表すことができます.

Defined in header <chrono>
Defined in namespace std::chrono
(C++11)
時間間隔
Original:
a time interval
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(クラステンプレート) [edit]

[編集] クロック

クロックは、開始点(またはエポック)と刻みレートで構成されています。例えば、クロックは1970年1月1日のエポックと、一秒刻みのtickを持ちます。 C++では3つのクロック·タイプを定義しています:

Defined in header <chrono>
Defined in namespace std::chrono
システム全体のリアルタイムクロックから壁時計時刻
Original:
wall clock time from the system-wide realtime clock
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(クラス) [edit]
調整されることの無い単調なクロック
Original:
monotonic clock that will never be adjusted
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(クラス) [edit]
有効なclockのうち、tick間隔が一番短いclock
Original:
the clock with the shortest tick period available
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(クラス) [edit]

[編集] 時点

時点では、特定の時計のエポックから経過した時間の長さです.
Original:
A time point is a duration of time that has passed since the epoch of specific clock.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Defined in header <chrono>
Defined in namespace std::chrono
a point in time
(クラステンプレート) [edit]

[編集] C形式の日付と時刻ライブラリ

また、提供されるようstd::time_tとして、Cスタイルの日付と時刻の関数であり、std::difftime、とCLOCKS_PER_SEC.
Original:
Also provided are the C-style date and time functions, such as std::time_t, std::difftime, and CLOCKS_PER_SEC.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集]

この例では、関数呼び出しの実行時間に関する情報を表示します
Original:
This example displays information about the execution time of a function call:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <iostream>
#include <chrono>
#include <ctime>
 
int fibonacci(int n)
{
    if (n < 3) return 1;
    return fibonacci(n-1) + fibonacci(n-2);
}
 
int main()
{
    std::chrono::time_point<std::chrono::system_clock> start, end;
    start = std::chrono::system_clock::now();
    int result = fibonacci(42);
    end = std::chrono::system_clock::now();
 
    int elapsed_seconds = std::chrono::duration_cast<std::chrono::seconds>
                             (end-start).count();
    std::time_t end_time = std::chrono::system_clock::to_time_t(end);
 
    std::cout << "finished computation at " << std::ctime(&end_time)
              << "elapsed time: " << elapsed_seconds << "s\n";
}

Possible output:

finished computation at Sat Jun 16 20:42:57 2012
elapsed time: 3s