]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl> |
2 | .\" | |
4b72fb64 | 3 | .\" %%%LICENSE_START(verbatim) |
fea681da MK |
4 | .\" Permission is granted to make and distribute verbatim copies of this |
5 | .\" manual provided the copyright notice and this permission notice are | |
6 | .\" preserved on all copies. | |
7 | .\" | |
8 | .\" Permission is granted to copy and distribute modified versions of this | |
9 | .\" manual under the conditions for verbatim copying, provided that the | |
10 | .\" entire resulting derived work is distributed under the terms of a | |
11 | .\" permission notice identical to this one. | |
c13182ef | 12 | .\" |
fea681da MK |
13 | .\" Since the Linux kernel and libraries are constantly changing, this |
14 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
15 | .\" responsibility for errors or omissions, or for damages resulting from | |
16 | .\" the use of the information contained herein. The author(s) may not | |
17 | .\" have taken the same level of care in the production of this manual, | |
18 | .\" which is licensed free of charge, as they might when working | |
19 | .\" professionally. | |
c13182ef | 20 | .\" |
fea681da MK |
21 | .\" Formatted or processed versions of this manual, if unaccompanied by |
22 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 23 | .\" %%%LICENSE_END |
fea681da | 24 | .\" |
cc4615cc | 25 | .TH TIMEGM 3 2007-07-26 "GNU" "Linux Programmer's Manual" |
fea681da | 26 | .SH NAME |
02011a43 | 27 | timegm, timelocal \- inverses of gmtime and localtime |
fea681da MK |
28 | .SH SYNOPSIS |
29 | .nf | |
30 | .B #include <time.h> | |
31 | .sp | |
b9f02710 | 32 | .BI "time_t timelocal(struct tm *" tm ); |
fea681da | 33 | .sp |
b9f02710 | 34 | .BI "time_t timegm(struct tm *" tm ); |
cc4615cc MK |
35 | .sp |
36 | .fi | |
37 | .in -4n | |
38 | Feature Test Macro Requirements for glibc (see | |
39 | .BR feature_test_macros (7)): | |
40 | .in | |
41 | .sp | |
42 | .BR timelocal (), | |
43 | .BR timegm (): | |
44 | _BSD_SOURCE || _SVID_SOURCE | |
fea681da MK |
45 | .SH DESCRIPTION |
46 | The functions | |
63aa9df0 | 47 | .BR timelocal () |
fea681da | 48 | and |
63aa9df0 | 49 | .BR timegm () |
02011a43 | 50 | are the inverses of |
fea681da MK |
51 | .BR localtime (3) |
52 | and | |
53 | .BR gmtime (3). | |
47297adb | 54 | .SH CONFORMING TO |
c8f2dd47 | 55 | These functions are nonstandard GNU extensions |
02011a43 MK |
56 | that are also present on the BSDs. |
57 | Avoid their use; see NOTES. | |
fea681da | 58 | .SH NOTES |
fea681da | 59 | The |
63aa9df0 | 60 | .BR timelocal () |
fea681da MK |
61 | function is equivalent to the POSIX standard function |
62 | .BR mktime (3). | |
63 | There is no reason to ever use it. | |
64 | .LP | |
65 | For a portable version of | |
63aa9df0 | 66 | .BR timegm (), |
fea681da MK |
67 | set the |
68 | .B TZ | |
69 | environment variable to UTC, call | |
fb186734 | 70 | .BR mktime (3) |
fea681da MK |
71 | and restore the value of |
72 | .BR TZ . | |
73 | Something like | |
74 | ||
a6e2f128 | 75 | .in +4n |
fea681da MK |
76 | .nf |
77 | #include <time.h> | |
78 | #include <stdlib.h> | |
79 | ||
c13182ef MK |
80 | time_t |
81 | my_timegm(struct tm *tm) | |
41798314 | 82 | { |
fea681da MK |
83 | time_t ret; |
84 | char *tz; | |
85 | ||
86 | tz = getenv("TZ"); | |
87 | setenv("TZ", "", 1); | |
88 | tzset(); | |
89 | ret = mktime(tm); | |
90 | if (tz) | |
91 | setenv("TZ", tz, 1); | |
92 | else | |
93 | unsetenv("TZ"); | |
94 | tzset(); | |
95 | return ret; | |
96 | } | |
97 | .fi | |
a6e2f128 | 98 | .in |
47297adb | 99 | .SH SEE ALSO |
fea681da MK |
100 | .BR gmtime (3), |
101 | .BR localtime (3), | |
102 | .BR mktime (3), | |
103 | .BR tzset (3) |