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

NAME

6       timegm, timelocal - inverses for 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

DESCRIPTION

16       The functions timelocal() and timegm() are the inverses to localtime(3)
17       and gmtime(3).
18

NOTES

20       These functions are GNU extensions.  The timelocal() function is equiv‐
21       alent  to the POSIX standard function mktime(3).  There is no reason to
22       ever use it.
23
24       For a portable version of timegm(), set the TZ environment variable  to
25       UTC, call mktime() and restore the value of TZ.  Something like
26
27              #include <time.h>
28              #include <stdlib.h>
29
30              time_t my_timegm (struct tm *tm) {
31                  time_t ret;
32                  char *tz;
33
34                  tz = getenv("TZ");
35                  setenv("TZ", "", 1);
36                  tzset();
37                  ret = mktime(tm);
38                  if (tz)
39                      setenv("TZ", tz, 1);
40                  else
41                      unsetenv("TZ");
42                  tzset();
43                  return ret;
44              }
45

CONFORMING TO

47       Not in POSIX.1-2001.  Present on the BSDs.
48

SEE ALSO

50       gmtime(3), localtime(3), mktime(3), tzset(3)
51
52
53
54GNU                               2001-12-26                         TIMEGM(3)
Impressum