gmtime_gmtime32_gmtime64

time_t 時刻値を tm 構造体に変換します。 これらの関数のセキュリティを強化したバージョンを使用できます。「gmtime_s_gmtime32_s_gmtime64_s」を参照してください。

構文

struct tm *gmtime( const time_t *sourceTime );
struct tm *_gmtime32( const __time32_t *sourceTime );
struct tm *_gmtime64( const __time64_t *sourceTime );

パラメーター

sourceTime
格納されている時刻へのポインター。 時刻は、世界協定時刻 (UTC: Coordinated Universal Time) の 1970 年 1 月 1 日の深夜 00:00:00 から経過した時間 (秒単位) を表します。

戻り値

tm 型の構造体へのポインター。 返された構造体の各フィールドには、sourceTime 引数を現地時刻ではなく UTC で評価した値が格納されています。 構造体の各フィールドは int 型で、次のとおりです:

フィールド 説明
tm_sec 秒 (0 - 59)。
tm_min 分 (0 - 59)。
tm_hour 時 (0 - 23)。
tm_mday 日 (1 - 31)。
tm_mon 月 (0 - 11、1 月 = 0)。
tm_year 年 (実際の西暦から 1900 を引いた数)
tm_wday 曜日 (0 - 6、日曜日 = 0)。
tm_yday 年内の通算日 (0 - 365、1 月 1 日 = 0)。
tm_isdst gmtime では常に 0。

32 ビット バージョンおよび 64 ビット バージョンの gmtimemktimemkgmtimelocaltime の各関数はすべて、1 スレッドあたり共通の tm 構造体を 1 つ使用して変換を行います。 これらの関数を呼び出すたびに、前の呼び出しの結果は破棄されます。 sourceTime が 1970 年 1 月 1 日の深夜 0 時よりも前の日付を示している場合、gmtimeNULL を返します。 エラーの戻り値はありません。

__time64_t 構造体を使用する _gmtime64 では、UTC の 3000 年 12 月 31 日の 23 時 59 分 59 秒までの日付を表すことができます。 _gmtime32 では、UTC の 2038 年 1 月 18 日の 23 時 59 分 59 秒までの日付のみを表します。 これらの関数の日付範囲の下限は、どちらも 1970 年 1 月 1 日の午前 0 時です。

gmtime_gmtime64 に評価されるインライン関数であり、time_t__time64_t が定義されている場合を除き _USE_32BIT_TIME_T と等価です。 コンパイラに time_t を従来の 32 ビットの time_t として解釈させる必要がある場合は、_USE_32BIT_TIME_T を定義できますが、そのためには gmtime_gmtime32 にインライン展開し、time_t__time32_t として定義します。 64 ビット プラットフォームでは許可されていないため、_USE_32BIT_TIME_T を使用することはお勧めしません。 いずれにしても、2038 年 1 月 18 日より後にアプリケーションでエラーが発生する可能性があります。

これらの関数では、パラメーターの検証が行われます。 sourceTimeNULL ポインターの場合、または sourceTime 値が負の場合、「パラメーターの検証」に説明されているように、これらの関数では無効なパラメーター ハンドラーが呼び出されます。 実行の継続が許可された場合、関数は NULL を返し、errnoEINVAL に設定します。

解説

_gmtime32 関数では、sourceTime 値を展開して、TIME.H に定義され、静的に割り当てられた tm 型の構造体に保存します。 sourceTime 値は、通常は time 関数の呼び出しにより取得されます。

既定では、この関数のグローバル状態の適用対象は、アプリケーションになります。 この動作を変更するには、「CRT でのグローバル状態」を参照してください。

要件

ルーチンによって返される値 必須の C ヘッダー 必須の C++ ヘッダー
gmtime_gmtime32_gmtime64 <time.h> <ctime> または <time.h>

互換性の詳細については、「 Compatibility」を参照してください。

// crt_gmtime.c
// compile with: /W3
// This program uses _gmtime64 to convert a long-
// integer representation of coordinated universal time
// to a structure named newtime, then uses asctime to
// convert this structure to an output string.

#include <time.h>
#include <stdio.h>

int main(void)
{
   struct tm *newtime;
   __int64 ltime;
   char buff[80];

   _time64( &ltime );

   // Obtain coordinated universal time:
   newtime = _gmtime64( &ltime ); // C4996
   // Note: _gmtime64 is deprecated; consider using _gmtime64_s
   asctime_s( buff, sizeof(buff), newtime );
   printf( "Coordinated universal time is %s\n", buff );
}
Coordinated universal time is Tue Feb 12 23:11:31 2002

関連項目

時間管理
asctime_wasctime
ctime_ctime32_ctime64_wctime_wctime32_wctime64
_ftime_ftime32_ftime64
gmtime_s_gmtime32_s_gmtime64_s
localtime_localtime32_localtime64
_mkgmtime_mkgmtime32_mkgmtime64
mktime_mktime32_mktime64
time_time32_time64