]> git.saurik.com Git - apple/libc.git/blob - stdtime/timegm.3
Libc-1158.50.2.tar.gz
[apple/libc.git] / stdtime / timegm.3
1 .\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl>
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .TH TIMEGM 3 2001-12-26 "GNU" "Linux Programmer's Manual"
24 .SH NAME
25 timegm, timelocal \- inverses for gmtime and localtime
26 .SH SYNOPSIS
27 .nf
28 .B #include <time.h>
29 .sp
30 .BI "time_t timelocal (struct tm *" tm );
31 .sp
32 .BI "time_t timegm (struct tm *" tm );
33 .SH DESCRIPTION
34 The functions
35 .B timelocal()
36 and
37 .B timegm()
38 are the inverses to
39 .BR localtime (3)
40 and
41 .BR gmtime (3).
42 .SH NOTES
43 These functions are GNU extensions.
44 The
45 .B timelocal()
46 function is equivalent to the POSIX standard function
47 .BR mktime (3).
48 There is no reason to ever use it.
49 .LP
50 For a portable version of
51 .BR timegm() ,
52 set the
53 .B TZ
54 environment variable to UTC, call
55 .B mktime()
56 and restore the value of
57 .BR TZ .
58 Something like
59
60 .RS
61 .nf
62 #include <time.h>
63 #include <stdlib.h>
64
65 time_t my_timegm (struct tm *tm) {
66 time_t ret;
67 char *tz;
68
69 tz = getenv("TZ");
70 setenv("TZ", "", 1);
71 tzset();
72 ret = mktime(tm);
73 if (tz)
74 setenv("TZ", tz, 1);
75 else
76 unsetenv("TZ");
77 tzset();
78 return ret;
79 }
80 .fi
81 .RE
82 .SH "SEE ALSO"
83 .BR gmtime (3),
84 .BR localtime (3),
85 .BR mktime (3),
86 .BR tzset (3)