1TIMEGM(3) Linux Programmer's Manual TIMEGM(3)
2
3
4
6 timegm, timelocal - inverses of gmtime and localtime
7
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
20 The functions timelocal() and timegm() are the inverses of localtime(3)
21 and gmtime(3).
22
24 These functions are nonstandard GNU extensions that are also present on
25 the BSDs. Avoid their use; see NOTES.
26
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 if (tz)
45 tz = strdup(tz);
46 setenv("TZ", "", 1);
47 tzset();
48 ret = mktime(tm);
49 if (tz) {
50 setenv("TZ", tz, 1);
51 free(tz);
52 } else
53 unsetenv("TZ");
54 tzset();
55 return ret;
56 }
57
59 gmtime(3), localtime(3), mktime(3), tzset(3)
60
62 This page is part of release 3.53 of the Linux man-pages project. A
63 description of the project, and information about reporting bugs, can
64 be found at http://www.kernel.org/doc/man-pages/.
65
66
67
68GNU 2013-07-04 TIMEGM(3)