gmtime_s_gmtime32_s_gmtime64_s

時刻の値を tm 構造体に変換します。 これらの関数は、「CRT のセキュリティ機能」で説明されているように、セキュリティが強化されたバージョンの _gmtime32_gmtime64 です。

構文

errno_t gmtime_s(
   struct tm* tmDest,
   const __time_t* sourceTime
);
errno_t _gmtime32_s(
   struct tm* tmDest,
   const __time32_t* sourceTime
);
errno_t _gmtime64_s(
   struct tm* tmDest,
   const __time64_t* sourceTime
);

パラメーター

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

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

戻り値

正常終了した場合は 0。 エラーが発生した場合、戻り値はエラー コードです。 エラー コードは Errno.h で定義されます。これらのエラーの一覧については、errno に関するページをご覧ください。

エラー条件

tmDest sourceTime Return tmDest の値
NULL any EINVAL 変更されません。
NULL ではありません (有効なメモリを指します) NULL EINVAL すべてのフィールドが-1 に設定されます。
NULL ではない < 0 EINVAL すべてのフィールドが-1 に設定されます。

パラメーターの検証」で説明されているように、最初の 2 つのエラー条件により、無効なパラメーター ハンドラーが呼び出されます。 実行の継続が許可された場合、これらの関数は errnoEINVAL に設定し、EINVAL を返します。

解説

_gmtime32_s 関数は、sourceTime 値を展開して、Time.h に定義された tm 型の構造体に保存します。 構造体のアドレスが tmDest に渡されます。 多くの場合、sourceTime の値は、time 関数の呼び出しにより取得されます。

構造体の各フィールドは 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_s では常に 0。

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

gmtime_s_gmtime64_s と評価されるインライン関数であり、time_t__time64_t と等価です。 コンパイラが time_t を古い 32 ビットの time_tとして解釈するよう強制する必要がある場合には、 _USE_32BIT_TIME_Tを定義します。 _USE_32BIT_TIME_T により、gmtime_s_gmtime32_s としてインライン化されます。 _USE_32BIT_TIME_T はお勧めしません。2038 年 1 月 18 日以降にアプリケーションがエラーになる可能性があり、64 ビット プラットフォームでは使用できないからです。

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

要件

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

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

// crt_gmtime64_s.c
// This program uses _gmtime64_s to convert a 64-bit
// integer representation of coordinated universal time
// to a structure named newtime, then uses asctime_s to
// convert this structure to an output string.

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

int main( void )
{
   struct tm newtime;
   __int64 ltime;
   char buf[26];
   errno_t err;

   _time64( &ltime );

   // Obtain coordinated universal time:
   err = _gmtime64_s( &newtime, &ltime );
   if (err)
   {
      printf("Invalid Argument to _gmtime64_s.");
   }

   // Convert to an ASCII representation
   err = asctime_s(buf, 26, &newtime);
   if (err)
   {
      printf("Invalid Argument to asctime_s.");
   }

   printf( "Coordinated universal time is %s\n",
           buf );
}
Coordinated universal time is Fri Apr 25 20:12:33 2003

関連項目

時間管理
asctime_s_wasctime_s
ctime_ctime32_ctime64_wctime_wctime32_wctime64
_ftime_ftime32_ftime64
gmtime_gmtime32_gmtime64
localtime_s_localtime32_s_localtime64_s
_mkgmtime_mkgmtime32_mkgmtime64
mktime_mktime32_mktime64
time_time32_time64