std:: timespec
From cppreference.net
C++
Date and time library
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定義済みヘッダー
<ctime>
|
||
|
struct
timespec
;
|
(C++17以降) | |
秒とナノ秒に分解された時間間隔を保持する構造体。
目次 |
データメンバ
| メンバー | 説明 |
|
std::time_t
tv_sec
|
秒単位の全体、値は >=
0
(公開メンバーオブジェクト) |
|
long
tv_nsec
|
ナノ秒、値の範囲は
[
0
,
999999999
]
(公開メンバーオブジェクト) |
tv_sec
と
tv_nsec
の宣言順序は未規定です。実装によっては
timespec
に他のデータメンバを追加する場合があります。
注記
tv_nsec
の型は一部のプラットフォームでは
long
long
ですが、これは現在C++では非準拠です。ただし、C言語ではC23以降で許可されています。
例
このコードを実行
#include <ctime> #include <iostream> int main() { std::timespec ts; std::timespec_get(&ts, TIME_UTC); char buff[0x80]; std::strftime(buff, sizeof buff, "%D %T", std::gmtime(&ts.tv_sec)); // auto [sec, nsec] = ts; // UB: structured bindings should not be used because the // declaration order and data member list are unspecified std::cout << "Current time: " << buff << " (UTC)\n" << "Raw timespec.tv_sec: " << ts.tv_sec << '\n' << "Raw timespec.tv_nsec: " << ts.tv_nsec << '\n'; }
出力例:
Current time: 04/06/23 12:03:31 (UTC) Raw timespec.tv_sec: 1680782611 Raw timespec.tv_nsec: 678437213
関連項目
|
(C++17)
|
指定された時間ベースに基づいて秒とナノ秒での暦時間を返す
(関数) |
|
暦時間型
(クラス) |
|
|
Cドキュメント
for
timespec
|
|