1TZSET(3) Linux Programmer's Manual TZSET(3)
2
3
4
6 tzset, tzname, timezone, daylight - initialize time conversion informa‐
7 tion
8
10 #include <time.h>
11
12 void tzset (void);
13
14 extern char *tzname[2];
15 extern long timezone;
16 extern int daylight;
17
19 The tzset() function initializes the tzname variable from the TZ envi‐
20 ronment variable. This function is automatically called by the other
21 time conversion functions that depend on the time zone. In a SysV-like
22 environment it will also set the variables timezone (seconds West of
23 GMT) and daylight (0 if this time zone does not have any daylight sav‐
24 ing time rules, non-zero if there is a time during the year when day‐
25 light saving time applies).
26
27 If the TZ variable does not appear in the environment, the tzname vari‐
28 able is initialized with the best approximation of local wall clock
29 time, as specified by the tzfile(5)-format file localtime found in the
30 system timezone directory (see below). (One also often sees
31 /etc/localtime used here, a symlink to the right file in the system
32 timezone directory.)
33
34 If the TZ variable does appear in the environment but its value is
35 empty or its value cannot be interpreted using any of the formats spec‐
36 ified below, Coordinated Universal Time (UTC) is used.
37
38 The value of TZ can be one of three formats. The first format is used
39 when there is no daylight saving time in the local time zone:
40
41 std offset
42
43 The std string specifies the name of the time zone and must be three or
44 more alphabetic characters. The offset string immediately follows std
45 and specifies the time value to be added to the local time to get Coor‐
46 dinated Universal Time (UTC). The offset is positive if the local time
47 zone is west of the Prime Meridian and negative if it is east. The
48 hour must be between 0 and 24, and the minutes and seconds 0 and 59.
49
50 The second format is used when there is daylight saving time:
51
52 std offset dst [offset],start[/time],end[/time]
53
54 There are no spaces in the specification. The initial std and offset
55 specify the standard time zone, as described above. The dst string and
56 offset specify the name and offset for the corresponding daylight sav‐
57 ing time zone. If the offset is omitted, it default to one hour ahead
58 of standard time.
59
60 The start field specifies when daylight saving time goes into effect
61 and the end field specifies when the change is made back to standard
62 time. These fields may have the following formats:
63
64 Jn This specifies the Julian day with n between 1 and 365. Febru‐
65 ary 29 is never counted even in leap years.
66
67 n This specifies the Julian day with n between 1 and 365. Febru‐
68 ary 29 is counted in leap years.
69
70 Mm.w.d This specifies day d (0 <= d <= 6) of week w (1 <= w <= 5) of
71 month m (1 <= m <= 12). Week 1 is the first week in which day d
72 occurs and week 5 is the last week in which day d occurs. Day 0
73 is a Sunday.
74
75 The time fields specify when, in the local time currently in effect,
76 the change to the other time occurs. If omitted, the default is
77 02:00:00.
78
79 Here is an example for New Zealand, where the standard time (NZST) is
80 12 hours ahead of UTC, and daylight saving time (NZDT), 13 hours ahead
81 of UTC, runs from the first Sunday in October to the third Sunday in
82 March, and the changeovers happen at the default time of 02:00:00:
83
84 TZ="NZST-12.00:00NZDT-13:00:00,M10.1.0,M3.3.0"
85
86 The third format specifies that the time zone information should be
87 read from a file:
88
89 :[filespec]
90
91 If the file specification filespec is omitted, the time zone informa‐
92 tion is read from the file localtime in the system timezone directory,
93 which nowadays usually is /usr/share/zoneinfo. This file is in
94 tzfile(5) format. If filespec is given, it specifies another
95 tzfile(5)-format file to read the time zone information from. If file‐
96 spec does not begin with a `/', the file specification is relative to
97 the system timezone directory.
98
99 Here's an example, once more for New Zealand:
100
101 TZ=":Pacific/Auckland"
102
104 The system time zone directory used depends on the (g)libc version.
105 Libc4 and libc5 use /usr/lib/zoneinfo, and, since libc-5.4.6, when this
106 doesn't work, will try /usr/share/zoneinfo. Glibc2 will use the envi‐
107 ronment variable TZDIR, when that exists. Its default depends on how
108 it was installed, but normally is /usr/share/zoneinfo.
109
110 This timezone directory contains the files
111 localtime local time zone file
112 posixrules rules for POSIX-style TZ's
113
114 Often /etc/localtime is a symlink to the file localtime or to the cor‐
115 rect time zone file in the system time zone directory.
116
118 SVr4, POSIX.1-2001, 4.3BSD
119
121 Note that the variable daylight does not indicate that daylight saving
122 time applies right now. It used to give the number of some algorithm
123 (see the variable tz_dsttime in gettimeofday(2)). It has been obsolete
124 for many years but is required by SUSv2.
125
126 4.3BSD had a function char *timezone(zone, dst) that returned the name
127 of the time zone corresponding to its first argument (minutes West of
128 GMT). If the second argument was 0, the standard name was used, other‐
129 wise the daylight saving time version.
130
132 date(1), gettimeofday(2), time(2), ctime(3), getenv(3), tzfile(5)
133
134
135
136 2001-11-13 TZSET(3)