]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/timegm.3
intro.1, _exit.2, access.2, alarm.2, alloc_hugepages.2, arch_prctl.2, bind.2, chdir...
[thirdparty/man-pages.git] / man3 / timegm.3
CommitLineData
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 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 ():
44_BSD_SOURCE || _SVID_SOURCE
fea681da
MK
45.SH DESCRIPTION
46The functions
63aa9df0 47.BR timelocal ()
fea681da 48and
63aa9df0 49.BR timegm ()
02011a43 50are the inverses of
fea681da
MK
51.BR localtime (3)
52and
53.BR gmtime (3).
47297adb 54.SH CONFORMING TO
c8f2dd47 55These functions are nonstandard GNU extensions
02011a43
MK
56that are also present on the BSDs.
57Avoid their use; see NOTES.
fea681da 58.SH NOTES
fea681da 59The
63aa9df0 60.BR timelocal ()
fea681da
MK
61function is equivalent to the POSIX standard function
62.BR mktime (3).
63There is no reason to ever use it.
64.LP
65For a portable version of
63aa9df0 66.BR timegm (),
fea681da
MK
67set the
68.B TZ
69environment variable to UTC, call
fb186734 70.BR mktime (3)
fea681da
MK
71and restore the value of
72.BR TZ .
73Something like
74
a6e2f128 75.in +4n
fea681da
MK
76.nf
77#include <time.h>
78#include <stdlib.h>
79
c13182ef
MK
80time_t
81my_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)