Share via


gmtime、_gmtime32、_gmtime64

時刻の値を構造体に変換します。これらの関数のセキュリティを強化したバージョンについては、「gmtime_s、_gmtime32_s、_gmtime64_s」を参照してください。

struct tm *gmtime( 
   const time_t *timer 
);
struct tm *_gmtime32( 
   const time32_t *timer 
);
struct tm *_gmtime64( 
   const __time64_t *timer 
);

パラメーター

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

戻り値

tm の構造体へのポインターを返します。返された構造体の各フィールドには、timer 引数を現地時刻ではなく 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。

gmtimemktimemkgmtime と localtime すべての 32 ビット バージョンと 64 ビット バージョンの変換にスレッドごとの tm の単一の構造を使用します。これらの関数の 1 種類に対する各呼び出しは前の呼び出しの結果を破棄します。timer が午前以前の日付を表す場合1970 年 1 月 1 日 1 gmtime はNULL を返します。エラーの戻り値はありません。

_gmtime64 は __time64_t 構造を使用する日付を 23:59 によって表されるを : _gmtime32 が 03:14 からのみ日付を表し593000 12 年 1 月 31 日のUTC: 1 年 1 月 07 日 19 時 2038 の UTC。これらの関数の日付範囲の下限は、どちらも 1970 年 1 月 1 日の午前零時です。

gmtime は _gmtime64 になりtime_t が __time64_t と等価のインライン関数です。コンパイラが time_t を従来の 32 ビット time_t として解釈するようにするには、_USE_32BIT_TIME_T を定義します。この定義を行うことにより、gmtime は _gmtime32 にインライン展開されます。この方法はお勧めしません。2038 年 1 月 18 日以降にアプリケーションでエラーが発生する可能性があり、64 ビット プラットフォームでは使用できないためです。

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

解説

_gmtime32 の関数は timer の値を受け取り TIME.H. で定義されている型 tm の静的に割り当てられた構造体に格納します。timer 値は通常、time 関数の呼び出しにより取得されます。

[!メモ]

対象の環境で夏時間が有効かどうかを確認してください。C ランタイム ライブラリで夏時間の計算を実行するための米国の規則を (DST) 前提としています。

必要条件

ルーチン

必須ヘッダー

gmtime

<time.h>

_gmtime32

<time.h>

_gmtime64

<time.h>

互換性の詳細については、「C ランタイム ライブラリ」の「互換性」を参照してください。

使用例

// 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 );
}
  

同等の .NET Framework 関数

参照

関連項目

時間管理

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