timegmのヘルプ・マニュアル
日本語 英語
timegm --help
man timegm
TIMEGM(3) Linux Programmer’s Manual TIMEGM(3)
名前
timegm, timelocal - gmtime と localtime の逆関数
書式
#include
time_t timelocal(struct tm *tm);
time_t timegm(struct tm *tm);
glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):
timelocal(), timegm(): _BSD_SOURCE || _SVID_SOURCE
説明
timelocal() 関 数 と timegm() 関数は、それぞれ localtime(3) 関数と
gmtime(3) 関数の逆関数である。
準拠
これらの関数は非標準で GNU の拡張である。 BSD 系にも存在する。これら の
使用は避けること。「注意」参照。
注意
timelocal() 関数は POSIX の標準関数 mktime(3) と同じものである。ので、
これを使う理由はないはずである。
timegm() を移植性があるようなかたちで実現するには、 TZ 環境変数 を UTC
に設定してから mktime(3) を呼んで、 TZ の値を取得すればよい。例えば次の
ようになるだろう。
#include
#include
time_t my_timegm (struct tm *tm)
{
time_t ret;
char *tz;
tz = getenv("TZ");
setenv("TZ", "", 1);
tzset();
ret = mktime(tm);
if (tz)
setenv("TZ", tz, 1);
else
unsetenv("TZ");
tzset();
return ret;
}
関連項目
gmtime(3), localtime(3), mktime(3), tzset(3)
GNU 2007-07-26 TIMEGM(3)
TIMEGM(3) Linux Programmer’s Manual TIMEGM(3)
NAME
timegm, timelocal - inverses of gmtime and localtime
SYNOPSIS
#include
time_t timelocal(struct tm *tm);
time_t timegm(struct tm *tm);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
timelocal(), timegm(): _BSD_SOURCE || _SVID_SOURCE
DESCRIPTION
The functions timelocal() and timegm() are the inverses of localtime(3)
and gmtime(3).
CONFORMING TO
These functions are non-standard GNU extensions that are also present
on the BSDs. Avoid their use; see NOTES.
NOTES
The timelocal() function is equivalent to the POSIX standard function
mktime(3). There is no reason to ever use it.
For a portable version of timegm(), set the TZ environment variable to
UTC, call mktime(3) and restore the value of TZ. Something like
#include
#include
time_t
my_timegm(struct tm *tm)
{
time_t ret;
char *tz;
tz = getenv("TZ");
setenv("TZ", "", 1);
tzset();
ret = mktime(tm);
if (tz)
setenv("TZ", tz, 1);
else
unsetenv("TZ");
tzset();
return ret;
}
SEE ALSO
gmtime(3), localtime(3), mktime(3), tzset(3)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
GNU 2007-07-26 TIMEGM(3)