]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/timegm.3
getgroups.2, gettimeofday.2, mincore.2, readv.2, stime.2, wait4.2, addseverity.3...
[thirdparty/man-pages.git] / man3 / timegm.3
CommitLineData
fea681da
MK
1.\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl>
2.\"
93015253 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.\"
fe0fefbf 25.TH TIMEGM 3 2015-03-02 "GNU" "Linux Programmer's Manual"
fea681da 26.SH NAME
02011a43 27timegm, 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
38Feature Test Macro Requirements for glibc (see
39.BR feature_test_macros (7)):
40.in
41.sp
42.BR timelocal (),
43.BR timegm ():
51c612fb
MK
44 Since glibc 2.19:
45 _DEFAULT_SOURCE
46 Glibc 2.19 and earlier:
47 _BSD_SOURCE || _SVID_SOURCE
fea681da
MK
48.SH DESCRIPTION
49The functions
63aa9df0 50.BR timelocal ()
fea681da 51and
63aa9df0 52.BR timegm ()
02011a43 53are the inverses of
fea681da
MK
54.BR localtime (3)
55and
56.BR gmtime (3).
cd6fe8e7
PH
57.SH ATTRIBUTES
58For an explanation of the terms used in this section, see
59.BR attributes (7).
60.TS
61allbox;
62lbw21 lb lb
63l l l.
64Interface Attribute Value
65T{
66.BR timelocal (),
67.BR timegm ()
68T} Thread safety MT-Safe env locale
69.TE
47297adb 70.SH CONFORMING TO
c8f2dd47 71These functions are nonstandard GNU extensions
02011a43
MK
72that are also present on the BSDs.
73Avoid their use; see NOTES.
fea681da 74.SH NOTES
fea681da 75The
63aa9df0 76.BR timelocal ()
fea681da
MK
77function is equivalent to the POSIX standard function
78.BR mktime (3).
79There is no reason to ever use it.
80.LP
81For a portable version of
63aa9df0 82.BR timegm (),
fea681da
MK
83set the
84.B TZ
85environment variable to UTC, call
fb186734 86.BR mktime (3)
fea681da
MK
87and restore the value of
88.BR TZ .
89Something like
90
a6e2f128 91.in +4n
fea681da
MK
92.nf
93#include <time.h>
94#include <stdlib.h>
95
c13182ef
MK
96time_t
97my_timegm(struct tm *tm)
41798314 98{
fea681da
MK
99 time_t ret;
100 char *tz;
101
102 tz = getenv("TZ");
00a9a899
JG
103 if (tz)
104 tz = strdup(tz);
fea681da
MK
105 setenv("TZ", "", 1);
106 tzset();
107 ret = mktime(tm);
00a9a899 108 if (tz) {
fea681da 109 setenv("TZ", tz, 1);
00a9a899
JG
110 free(tz);
111 } else
fea681da
MK
112 unsetenv("TZ");
113 tzset();
114 return ret;
115}
116.fi
a6e2f128 117.in
47297adb 118.SH SEE ALSO
fea681da
MK
119.BR gmtime (3),
120.BR localtime (3),
121.BR mktime (3),
122.BR tzset (3)