1TIMEGM(3)                  Linux Programmer's Manual                 TIMEGM(3)
2
3
4

NAME

6       timegm, timelocal - inverses of gmtime and localtime
7

SYNOPSIS

9       #include <time.h>
10
11       time_t timelocal(struct tm *tm);
12
13       time_t timegm(struct tm *tm);
14
15   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
16
17       timelocal(), timegm(): _BSD_SOURCE || _SVID_SOURCE
18

DESCRIPTION

20       The functions timelocal() and timegm() are the inverses of localtime(3)
21       and gmtime(3).
22

CONFORMING TO

24       These functions are non-standard GNU extensions that are  also  present
25       on the BSDs.  Avoid their use; see NOTES.
26

NOTES

28       The  timelocal()  function is equivalent to the POSIX standard function
29       mktime(3).  There is no reason to ever use it.
30
31       For a portable version of timegm(), set the TZ environment variable  to
32       UTC, call mktime(3) and restore the value of TZ.  Something like
33
34           #include <time.h>
35           #include <stdlib.h>
36
37           time_t
38           my_timegm(struct tm *tm)
39           {
40               time_t ret;
41               char *tz;
42
43               tz = getenv("TZ");
44               setenv("TZ", "", 1);
45               tzset();
46               ret = mktime(tm);
47               if (tz)
48                   setenv("TZ", tz, 1);
49               else
50                   unsetenv("TZ");
51               tzset();
52               return ret;
53           }
54

SEE ALSO

56       gmtime(3), localtime(3), mktime(3), tzset(3)
57

COLOPHON

59       This  page  is  part of release 3.22 of the Linux man-pages project.  A
60       description of the project, and information about reporting  bugs,  can
61       be found at http://www.kernel.org/doc/man-pages/.
62
63
64
65GNU                               2007-07-26                         TIMEGM(3)
Impressum