localedef.1, access.2, ioctl_console.2, ioctl_fslabel.2, openat2.2, write.2, dlsym...
[man-pages.git] / man3 / tzset.3
blobc80da53f8ba49ff9ddfa9cd260f9aa951ce4b140
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
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 .\" References consulted:
26 .\"     Linux libc source code
27 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
28 .\"     386BSD man pages
29 .\" Modified Sun Jul 25 11:01:58 1993 by Rik Faith (faith@cs.unc.edu)
30 .\" Modified 2001-11-13, aeb
31 .\" Modified 2004-12-01 mtk and Martin Schulze <joey@infodrom.org>
32 .\"
33 .TH TZSET 3  2021-03-22 "" "Linux Programmer's Manual"
34 .SH NAME
35 tzset, tzname, timezone, daylight \- initialize time conversion information
36 .SH SYNOPSIS
37 .nf
38 .B #include <time.h>
39 .PP
40 .B void tzset(void);
41 .PP
42 .BI "extern char *" tzname [2];
43 .BI "extern long " timezone ;
44 .BI "extern int " daylight ;
45 .fi
46 .PP
47 .RS -4
48 Feature Test Macro Requirements for glibc (see
49 .BR feature_test_macros (7)):
50 .RE
51 .PP
52 .BR tzset ():
53 .nf
54     _POSIX_C_SOURCE
55 .fi
56 .PP
57 .IR tzname :
58 .nf
59     _POSIX_C_SOURCE
60 .fi
61 .PP
62 .IR timezone ,
63 .IR daylight :
64 .nf
65     _XOPEN_SOURCE
66         || /* Glibc since 2.19: */ _DEFAULT_SOURCE
67         || /* Glibc <= 2.19: */ _SVID_SOURCE
68 .fi
69 .SH DESCRIPTION
70 The
71 .BR tzset ()
72 function initializes the \fItzname\fP variable from the
73 .B TZ
74 environment variable.
75 This function is automatically called by the
76 other time conversion functions that depend on the timezone.
77 In a System-V-like environment, it will also set the variables \fItimezone\fP
78 (seconds West of UTC) and \fIdaylight\fP (to 0 if this timezone does not
79 have any daylight saving time rules, or to nonzero if there is a time,
80 past, present, or future when daylight saving time applies).
81 .PP
82 If the
83 .B TZ
84 variable does not appear in the environment, the system timezone is used.
85 The system timezone is configured by copying, or linking, a file in the
86 .BR tzfile (5)
87 format to
88 .IR /etc/localtime .
89 A timezone database of these files may be located in the system
90 timezone directory (see the \fBFILES\fP section below).
91 .PP
92 If the
93 .B TZ
94 variable does appear in the environment, but its value is empty,
95 or its value cannot be interpreted using any of the formats specified
96 below, then Coordinated Universal Time (UTC) is used.
97 .PP
98 The value of
99 .B TZ
100 can be one of two formats.
101 The first format is a string of characters that directly represent the
102 timezone to be used:
104 .in +4n
106 .IR "std offset" [ dst [ offset ][, start [ /time ], end [ /time ]]]
110 There are no spaces in the specification.
111 The \fIstd\fP string specifies an abbreviation for the timezone and must be
112 three or more alphabetic characters.
113 When enclosed between the less-than (<) and greater-than (>) signs, the
114 characters set is expanded to include the plus (+) sign, the minus (-)
115 sign, and digits.
116 The \fIoffset\fP string immediately
117 follows \fIstd\fP and specifies the time value to be added to the local
118 time to get Coordinated Universal Time (UTC).
119 The \fIoffset\fP is positive
120 if the local timezone is west of the Prime Meridian and negative if it is
121 east.
122 The hour must be between 0 and 24, and the minutes and seconds 00 and 59:
124 .in +4n
126 .RI [ + | \- ] hh [ :mm [ :ss ]]
130 The \fIdst\fP string and \fIoffset\fP specify the name and offset for the
131 corresponding daylight saving timezone.
132 If the offset is omitted,
133 it defaults to one hour ahead of standard time.
135 The \fIstart\fP field specifies when daylight saving time goes into
136 effect and the \fIend\fP field specifies when the change is made back to
137 standard time.
138 These fields may have the following formats:
140 J\fIn\fP
141 This specifies the Julian day with \fIn\fP between 1 and 365.
142 Leap days are not counted.
143 In this format, February 29 can't be represented;
144 February 28 is day 59, and March 1 is always day 60.
146 .I n
147 This specifies the zero-based Julian day with \fIn\fP between 0 and 365.
148 February 29 is counted in leap years.
150 M\fIm\fP.\fIw\fP.\fId\fP
151 This specifies day \fId\fP (0 <= \fId\fP <= 6) of week \fIw\fP
152 (1 <= \fIw\fP <= 5) of month \fIm\fP (1 <= \fIm\fP <= 12).
153 Week 1 is
154 the first week in which day \fId\fP occurs and week 5 is the last week
155 in which day \fId\fP occurs.
156 Day 0 is a Sunday.
158 The \fItime\fP fields specify when, in the local time currently in effect,
159 the change to the other time occurs.
160 If omitted, the default is 02:00:00.
162 Here is an example for New Zealand,
163 where the standard time (NZST) is 12 hours ahead of UTC,
164 and daylight saving time (NZDT), 13 hours ahead of UTC,
165 runs from the first Sunday in October to the third Sunday in March,
166 and the changeovers happen at the default time of 02:00:00:
168 .in +4n
170 TZ="NZST\-12:00:00NZDT\-13:00:00,M10.1.0,M3.3.0"
174 The second format specifies that the timezone information should be read
175 from a file:
177 .in +4n
179 :[filespec]
183 If the file specification \fIfilespec\fP is omitted, or its value cannot
184 be interpreted, then Coordinated Universal Time (UTC) is used.
185 If \fIfilespec\fP is given, it specifies another
186 .BR tzfile (5)-format
187 file to read the timezone information from.
188 If \fIfilespec\fP does not begin with a \(aq/\(aq, the file specification is
189 relative to the system timezone directory.
190 If the colon is omitted each
191 of the above \fBTZ\fP formats will be tried.
193 Here's an example, once more for New Zealand:
195 .in +4n
197 TZ=":Pacific/Auckland"
200 .SH ENVIRONMENT
202 .B TZ
203 If this variable is set its value takes precedence over the system
204 configured timezone.
206 .B TZDIR
207 If this variable is set its value takes precedence over the system
208 configured timezone database directory path.
209 .SH FILES
211 .I /etc/localtime
212 The system timezone file.
214 .I /usr/share/zoneinfo/
215 The system timezone database directory.
217 .I /usr/share/zoneinfo/posixrules
218 When a TZ string includes a dst timezone without anything following it,
219 then this file is used for the start/end rules.
220 It is in the
221 .BR tzfile (5)
222 format.
223 By default, the zoneinfo Makefile hard links it to the
224 .IR America/New_York " tzfile."
226 Above are the current standard file locations, but they are
227 configurable when glibc is compiled.
228 .SH ATTRIBUTES
229 For an explanation of the terms used in this section, see
230 .BR attributes (7).
231 .ad l
234 allbox;
235 lbx lb lb
236 l l l.
237 Interface       Attribute       Value
239 .BR tzset ()
240 T}      Thread safety   MT-Safe env locale
244 .sp 1
245 .SH CONFORMING TO
246 POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
247 .SH NOTES
248 4.3BSD had a function
249 .BI "char *timezone(" zone ", " dst )
250 that returned the
251 name of the timezone corresponding to its first argument (minutes
252 West of UTC).
253 If the second argument was 0, the standard name was used,
254 otherwise the daylight saving time version.
255 .SH SEE ALSO
256 .BR date (1),
257 .BR gettimeofday (2),
258 .BR time (2),
259 .BR ctime (3),
260 .BR getenv (3),
261 .BR tzfile (5)