OSDN Git Service

c6bf7851812a0fab3c904cf1f068ee2ab8f4e6a4
[linuxjm/LDP_man-pages.git] / original / man3 / timegm.3
1 .\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl>
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
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.
12 .\"
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.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .TH TIMEGM 3 2013-07-04 "GNU" "Linux Programmer's Manual"
26 .SH NAME
27 timegm, timelocal \- inverses of gmtime and localtime
28 .SH SYNOPSIS
29 .nf
30 .B #include <time.h>
31 .sp
32 .BI "time_t timelocal(struct tm *" tm );
33 .sp
34 .BI "time_t timegm(struct tm *" tm );
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
45 .SH DESCRIPTION
46 The functions
47 .BR timelocal ()
48 and
49 .BR timegm ()
50 are the inverses of
51 .BR localtime (3)
52 and
53 .BR gmtime (3).
54 .SH CONFORMING TO
55 These functions are nonstandard GNU extensions
56 that are also present on the BSDs.
57 Avoid their use; see NOTES.
58 .SH NOTES
59 The
60 .BR timelocal ()
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
66 .BR timegm (),
67 set the
68 .B TZ
69 environment variable to UTC, call
70 .BR mktime (3)
71 and restore the value of
72 .BR TZ .
73 Something like
74
75 .in +4n
76 .nf
77 #include <time.h>
78 #include <stdlib.h>
79
80 time_t
81 my_timegm(struct tm *tm)
82 {
83     time_t ret;
84     char *tz;
85
86     tz = getenv("TZ");
87     if (tz)
88         tz = strdup(tz);
89     setenv("TZ", "", 1);
90     tzset();
91     ret = mktime(tm);
92     if (tz) {
93         setenv("TZ", tz, 1);
94         free(tz);
95     } else
96         unsetenv("TZ");
97     tzset();
98     return ret;
99 }
100 .fi
101 .in
102 .SH SEE ALSO
103 .BR gmtime (3),
104 .BR localtime (3),
105 .BR mktime (3),
106 .BR tzset (3)
107 .SH COLOPHON
108 This page is part of release 3.67 of the Linux
109 .I man-pages
110 project.
111 A description of the project,
112 information about reporting bugs,
113 and the latest version of this page,
114 can be found at
115 \%http://www.kernel.org/doc/man\-pages/.