gmtime、_gmtime64
時刻の値を構造体に変換します。
struct tm *gmtime(
const time_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
gmtime、mktime、localtime の各関数は、結果を格納するために、静的に割り当てられた 1 つの同じ構造体を使用します。これらの関数を呼び出すたびに、前の呼び出しの結果は破棄されます。timer が 1970 年 1 月 1 日 00:00:00 より前の日付を表す場合、gmtime は NULL を返します。エラーの戻り値はありません。
__time64_t 構造体を使用する _gmtime64 は、UTC 3000 年 12 月 31 日の 23:59:59 までの日時を表すことができます。gmtime は、UTC 2038 年 1 月 18 日の 19:14:07 までしか表せません。これらの関数の日付範囲の下限は、どちらも 1970 年 1 月 1 日の午前零時です。
解説
gmtime 関数は、timer 値を展開して、静的に割り当てられた tm 型の構造体に格納します。この構造体は TIME.H で定義されています。timer の値は、通常、time 関数で取得されます。
メモ 対象の環境で夏時間が有効かどうかを調べてください。C ランタイム ライブラリでは、アメリカ合衆国の規則を前提に夏時間 (DST: Daylight Saving Time) を計算します。
必要条件
ルーチン | 必須ヘッダー | 互換性 |
---|---|---|
gmtime | <time.h> | ANSI、Win 98、Win Me、Win NT、Win 2000、Win XP |
_gmtime64 | <time.h> | Win 98、Win Me、Win NT、Win 2000、Win XP |
互換性の詳細については、「C ランタイム ライブラリ」の「互換性」を参照してください。
ライブラリ
C ランタイム ライブラリのすべてのバージョン。
例
// crt_gmtime.c
/* 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;
_time64( <ime );
/* Obtain coordinated universal time: */
newtime = _gmtime64( <ime );
printf( "Coordinated universal time is %s\n",
asctime( newtime ) );
}
出力例
Coordinated universal time is Tue Feb 12 23:11:31 2002
参照
時間管理 | asctime | ctime | _ftime | localtime | mktime | time | ランタイム ルーチンおよび同等の .NET Framework 関数