]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/tzset.3
random.4: spfix
[thirdparty/man-pages.git] / man3 / tzset.3
CommitLineData
fea681da
MK
1.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
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.
c13182ef 11.\"
fea681da
MK
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.
c13182ef 19.\"
fea681da
MK
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.\" References consulted:
24.\" Linux libc source code
25.\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
26.\" 386BSD man pages
27.\" Modified Sun Jul 25 11:01:58 1993 by Rik Faith (faith@cs.unc.edu)
28.\" Modified 2001-11-13, aeb
122dff10
MK
29.\" Modified 2004-12-01 mtk and Martin Schulze <joey@infodrom.org>
30.\"
5a554f8e 31.TH TZSET 3 2012-03-25 "" "Linux Programmer's Manual"
fea681da
MK
32.SH NAME
33tzset, tzname, timezone, daylight \- initialize time conversion information
34.SH SYNOPSIS
35.nf
36.B #include <time.h>
37.sp
38.B void tzset (void);
39.sp
40.BI "extern char *" tzname [2];
41.BI "extern long " timezone ;
42.BI "extern int " daylight ;
43.fi
cc4615cc
MK
44.sp
45.in -4n
46Feature Test Macro Requirements for glibc (see
47.BR feature_test_macros (7)):
48.in
49.sp
50.BR tzset ():
0f200f07 51_POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _POSIX_SOURCE
cc4615cc
MK
52.br
53.IR tzname :
0f200f07 54_POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _POSIX_SOURCE
cc4615cc
MK
55.br
56.IR timezone :
57_SVID_SOURCE || _XOPEN_SOURCE
58.br
59.IR daylight :
60_SVID_SOURCE || _XOPEN_SOURCE
fea681da 61.SH DESCRIPTION
60a90ecd
MK
62The
63.BR tzset ()
64function initializes the \fItzname\fP variable from the
097585ed
MK
65.B TZ
66environment variable.
c13182ef 67This function is automatically called by the
5b0dc1ba 68other time conversion functions that depend on the timezone.
464ba7fc 69In a System-V-like environment, it will also set the variables \fItimezone\fP
750d65df 70(seconds West of UTC) and \fIdaylight\fP (to 0 if this timezone does not
464ba7fc 71have any daylight saving time rules, or to nonzero if there is a time during
e2905dc1 72the year when daylight saving time applies).
fea681da 73.PP
097585ed
MK
74If the
75.B TZ
76variable does not appear in the environment, the \fItzname\fP
fea681da
MK
77variable is initialized with the best approximation of local wall clock
78time, as specified by the
79.BR tzfile (5)-format
80file \fIlocaltime\fP
81found in the system timezone directory (see below).
82(One also often sees
83.I /etc/localtime
84used here, a symlink to the right file in the system timezone directory.)
85.PP
097585ed
MK
86If the
87.B TZ
88variable does appear in the environment but its value is empty
fea681da
MK
89or its value cannot be interpreted using any of the formats specified
90below, Coordinated Universal Time (UTC) is used.
91.PP
097585ed
MK
92The value of
93.B TZ
94can be one of three formats.
c13182ef 95The first format is used
5b0dc1ba 96when there is no daylight saving time in the local timezone:
fea681da
MK
97.sp
98.RS
99.I std offset
100.RE
101.sp
5b0dc1ba 102The \fIstd\fP string specifies the name of the timezone and must be
c13182ef
MK
103three or more alphabetic characters.
104The \fIoffset\fP string immediately
fea681da 105follows \fIstd\fP and specifies the time value to be added to the local
c13182ef
MK
106time to get Coordinated Universal Time (UTC).
107The \fIoffset\fP is positive
5b0dc1ba 108if the local timezone is west of the Prime Meridian and negative if it is
c13182ef
MK
109east.
110The hour must be between 0 and 24, and the minutes and seconds
fea681da
MK
1110 and 59.
112.PP
113The second format is used when there is daylight saving time:
114.sp
115.RS
116.I std offset dst [offset],start[/time],end[/time]
117.RE
118.sp
c13182ef
MK
119There are no spaces in the specification.
120The initial \fIstd\fP and
5b0dc1ba 121\fIoffset\fP specify the standard timezone, as described above.
c13182ef 122The \fIdst\fP string and \fIoffset\fP specify the name and offset for the
5b0dc1ba 123corresponding daylight saving timezone.
c13182ef 124If the offset is omitted,
e2905dc1 125it default to one hour ahead of standard time.
fea681da 126.PP
e2905dc1 127The \fIstart\fP field specifies when daylight saving time goes into
fea681da 128effect and the \fIend\fP field specifies when the change is made back to
c13182ef
MK
129standard time.
130These fields may have the following formats:
fea681da
MK
131.TP
132J\fIn\fP
c13182ef 133This specifies the Julian day with \fIn\fP between 1 and 365.
567e764a
MK
134Leap days are not counted.
135In this format, February 29 can't be represented;
136February 28 is day 59, and March 1 is always day 60.
c13182ef 137.TP
fea681da 138.I n
567e764a 139This specifies the zero-based Julian day with \fIn\fP between 0 and 365.
c13182ef
MK
140February 29 is counted in leap years.
141.TP
fea681da 142M\fIm\fP.\fIw\fP.\fId\fP
c13182ef
MK
143This specifies day \fId\fP (0 <= \fId\fP <= 6) of week \fIw\fP
144(1 <= \fIw\fP <= 5) of month \fIm\fP (1 <= \fIm\fP <= 12).
145Week 1 is
146the first week in which day \fId\fP occurs and week 5 is the last week
147in which day \fId\fP occurs.
148Day 0 is a Sunday.
fea681da
MK
149.PP
150The \fItime\fP fields specify when, in the local time currently in effect,
c13182ef
MK
151the change to the other time occurs.
152If omitted, the default is 02:00:00.
e2905dc1 153
c13182ef
MK
154Here is an example for New Zealand,
155where the standard time (NZST) is 12 hours ahead of UTC,
156and daylight saving time (NZDT), 13 hours ahead of UTC,
e2905dc1
MK
157runs from the first Sunday in October to the third Sunday in March,
158and the changeovers happen at the default time of 02:00:00:
159.nf
160
4b9999d6 161 TZ="NZST-12:00:00NZDT-13:00:00,M10.1.0,M3.3.0"
e2905dc1 162.fi
fea681da 163.PP
5b0dc1ba 164The third format specifies that the timezone information should be read
fea681da
MK
165from a file:
166.sp
167.RS
168:[filespec]
169.RE
170.sp
5b0dc1ba 171If the file specification \fIfilespec\fP is omitted, the timezone
fea681da
MK
172information is read from the file
173.I localtime
174in the system timezone directory, which nowadays usually is
175.IR /usr/share/zoneinfo .
176This file is in
177.BR tzfile (5)
c13182ef
MK
178format.
179If \fIfilespec\fP is given, it specifies another
fea681da 180.BR tzfile (5)-format
5b0dc1ba 181file to read the timezone information from.
f81fb444 182If \fIfilespec\fP does not begin with a \(aq/\(aq, the file specification is
fea681da 183relative to the system timezone directory.
e2905dc1
MK
184.PP
185Here's an example, once more for New Zealand:
186.nf
187
188 TZ=":Pacific/Auckland"
189.fi
fea681da 190.SH FILES
5b0dc1ba 191The system timezone directory used depends on the (g)libc version.
fea681da
MK
192Libc4 and libc5 use
193.IR /usr/lib/zoneinfo ,
194and, since libc-5.4.6,
195when this doesn't work, will try
196.IR /usr/share/zoneinfo .
097585ed
MK
197Glibc2 will use the environment variable
198.BR TZDIR ,
199when that exists.
fea681da
MK
200Its default depends on how it was installed, but normally is
201.IR /usr/share/zoneinfo .
202.LP
203This timezone directory contains the files
204.nf
5b0dc1ba 205localtime local timezone file
fea681da
MK
206posixrules rules for POSIX-style TZ's
207.fi
208.LP
209Often
210.I /etc/localtime
211is a symlink to the file
212.I localtime
5b0dc1ba 213or to the correct timezone file in the system timezone directory.
fea681da 214.SH "CONFORMING TO"
44a2c328 215SVr4, POSIX.1-2001, 4.3BSD.
fea681da
MK
216.SH NOTES
217Note that the variable \fIdaylight\fP does not indicate that daylight
c13182ef
MK
218saving time applies right now.
219It used to give the number of some
fea681da
MK
220algorithm (see the variable \fItz_dsttime\fP in
221.BR gettimeofday (2)).
222It has been obsolete for many years but is required by SUSv2.
223.LP
122dff10
MK
2244.3BSD had a function
225.BI "char *timezone(" zone ", " dst )
226that returned the
5b0dc1ba 227name of the timezone corresponding to its first argument (minutes
750d65df 228West of UTC).
c13182ef 229If the second argument was 0, the standard name was used,
e2905dc1 230otherwise the daylight saving time version.
fea681da
MK
231.SH "SEE ALSO"
232.BR date (1),
233.BR gettimeofday (2),
234.BR time (2),
235.BR ctime (3),
236.BR getenv (3),
237.BR tzfile (5)