指定された時間の基準に基づいて、最初の引数が指す間隔を現在のカレンダーの時間に設定します。
構文
int timespec_get( // See note in remarks section about linkage
struct timespec* const time_spec,
int const base
);
int _timespec32_get(
struct _timespec32* const time_spec,
int const base
);
int _timespec64_get(
struct _timespec64* const time_spec,
int const base
);
パラメーター
time_spec
エポックの開始以降の時間 (秒およびナノ秒単位) に設定される構造体へのポインター。
base
時間の基準を指定する実装固有の値 (0 以外)。
戻り値
成功すると値は base になり、失敗すると 0 を返します。
解説
timespec_get 関数は、 time_spec 引数が指す構造体で現在の値を設定します。 構造体のすべてのバージョンには、 tv_sec 、 tv_nsecというメンバーが存在します。
tv_sec 値は整数の秒に設定され、 tv_nsec はナノ秒の整数に設定されます ( baseによって指定されるエポックの開始以降の、システム クロックの解像度に丸められます)。
Microsoft 固有の仕様
これらの関数は、 TIME_UTC 値として base のみをサポートしています。
TIME_UTC は、 time_spec の値を、エポック開始からの秒数とナノ秒 (1970 年 1 月 1 日午前 0 時、世界協定時刻 (UTC) ) に設定します。
_timespec32では、 tv_sec は __time32_t 値です。
_timespec64では、 tv_sec は __time64_t 値です。
timespecでは、 tv_sec は time_t 型です。この長さは、プロセッサ マクロ _USE_32BIT_TIME_T が定義されているかどうかに応じて 32 ビットまたは 64 ビットになります。
timespec_get関数は、_timespec32_getが定義されている場合に_USE_32BIT_TIME_Tを呼び出すインライン関数です。それ以外の場合は_timespec64_getを呼び出します。
Microsoft 固有の終了
既定では、この関数のグローバル状態の適用対象は、アプリケーションになります。 この動作を変更するには、「CRT でのグローバル状態」を参照してください。
注
Windows SDK バージョン 10.0.26100.6901 と Visual Studio 2026 以降を一緒に使用する場合、 timespec_get は static inline されなくなります (内部リンケージ)。 代わりに、 inline (外部リンケージ) です。
前の動作に戻すには、CRT ヘッダーを含める前に #define _STATIC_INLINE_UCRT_FUNCTIONS=1 します。 既定では、_STATIC_INLINE_UCRT_FUNCTIONS は 0 に設定されています。
この変更により、UCRT が C++ 標準に準拠し、C++ モジュールとの互換性が向上します。
要件
| ルーチンによって返される値 | 必須ヘッダー |
|---|---|
timespec_get、 _timespec32_get、 _timespec64_get |
C: <time.h>、C++: <ctime> または <time.h> |
互換性の詳細については、「 Compatibility」を参照してください。
関連項目
時間管理
asctime, _wasctime
asctime_s, _wasctime_s
_ftime、 _ftime32、 _ftime64
gmtime、 _gmtime32、 _gmtime64
gmtime_s、 _gmtime32_s、 _gmtime64_s
localtime、 _localtime32、 _localtime64
localtime_s、 _localtime32_s、 _localtime64_s
time、 _time32、 _time64
_utime、 _utime32、 _utime64、 _wutime、 _wutime32、 _wutime64