1TZSET(3)                   Linux Programmer's Manual                  TZSET(3)
2
3
4

NAME

6       tzset, tzname, timezone, daylight - initialize time conversion informa‐
7       tion
8

SYNOPSIS

10       #include <time.h>
11
12       void tzset (void);
13
14       extern char *tzname[2];
15       extern long timezone;
16       extern int daylight;
17
18   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
19
20       tzset(): _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE
21       tzname: _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE
22       timezone: _SVID_SOURCE || _XOPEN_SOURCE
23       daylight: _SVID_SOURCE || _XOPEN_SOURCE
24

DESCRIPTION

26       The tzset() function initializes the tzname variable from the TZ  envi‐
27       ronment  variable.   This function is automatically called by the other
28       time conversion functions that depend on the timezone.  In a  System-V-
29       like  environment it will also set the variables timezone (seconds West
30       of GMT) and daylight (0 if this timezone does  not  have  any  daylight
31       saving  time  rules,  non-zero  if there is a time during the year when
32       daylight saving time applies).
33
34       If the TZ variable does not appear in the environment, the tzname vari‐
35       able  is  initialized  with  the best approximation of local wall clock
36       time, as specified by the tzfile(5)-format file localtime found in  the
37       system   timezone   directory   (see  below).   (One  also  often  sees
38       /etc/localtime used here, a symlink to the right  file  in  the  system
39       timezone directory.)
40
41       If  the  TZ  variable  does  appear in the environment but its value is
42       empty or its value cannot be interpreted using any of the formats spec‐
43       ified below, Coordinated Universal Time (UTC) is used.
44
45       The  value of TZ can be one of three formats.  The first format is used
46       when there is no daylight saving time in the local timezone:
47
48              std offset
49
50       The std string specifies the name of the timezone and must be three  or
51       more  alphabetic characters.  The offset string immediately follows std
52       and specifies the time value to be added to the local time to get Coor‐
53       dinated  Universal  Time  (UTC).   The  offset is positive if the local
54       timezone is west of the Prime Meridian and negative if it is east.  The
55       hour must be between 0 and 24, and the minutes and seconds 0 and 59.
56
57       The second format is used when there is daylight saving time:
58
59              std offset dst [offset],start[/time],end[/time]
60
61       There  are  no spaces in the specification.  The initial std and offset
62       specify the standard timezone, as described above.  The dst string  and
63       offset  specify the name and offset for the corresponding daylight sav‐
64       ing timezone.  If the offset is omitted, it default to one  hour  ahead
65       of standard time.
66
67       The  start  field  specifies when daylight saving time goes into effect
68       and the end field specifies when the change is made  back  to  standard
69       time.  These fields may have the following formats:
70
71       Jn     This  specifies the Julian day with n between 1 and 365.  Febru‐
72              ary 29 is never counted even in leap years.
73
74       n      This specifies the Julian day with n between 0 and 365.   Febru‐
75              ary 29 is counted in leap years.
76
77       Mm.w.d This  specifies  day  d (0 <= d <= 6) of week w (1 <= w <= 5) of
78              month m (1 <= m <= 12).  Week 1 is the first week in which day d
79              occurs and week 5 is the last week in which day d occurs.  Day 0
80              is a Sunday.
81
82       The time fields specify when, in the local time  currently  in  effect,
83       the  change  to  the  other  time  occurs.   If omitted, the default is
84       02:00:00.
85
86       Here is an example for New Zealand, where the standard time  (NZST)  is
87       12  hours ahead of UTC, and daylight saving time (NZDT), 13 hours ahead
88       of UTC, runs from the first Sunday in October to the  third  Sunday  in
89       March, and the changeovers happen at the default time of 02:00:00:
90
91           TZ="NZST-12.00:00NZDT-13:00:00,M10.1.0,M3.3.0"
92
93       The third format specifies that the timezone information should be read
94       from a file:
95
96              :[filespec]
97
98       If the file specification filespec is omitted, the timezone information
99       is read from the file localtime in the system timezone directory, which
100       nowadays usually is /usr/share/zoneinfo.  This  file  is  in  tzfile(5)
101       format.   If  filespec  is given, it specifies another tzfile(5)-format
102       file to read the timezone information from.  If filespec does not begin
103       with  a  '/', the file specification is relative to the system timezone
104       directory.
105
106       Here's an example, once more for New Zealand:
107
108           TZ=":Pacific/Auckland"
109

FILES

111       The system timezone directory used  depends  on  the  (g)libc  version.
112       Libc4 and libc5 use /usr/lib/zoneinfo, and, since libc-5.4.6, when this
113       doesn't work, will try /usr/share/zoneinfo.  Glibc2 will use the  envi‐
114       ronment  variable  TZDIR, when that exists.  Its default depends on how
115       it was installed, but normally is /usr/share/zoneinfo.
116
117       This timezone directory contains the files
118       localtime      local timezone file
119       posixrules     rules for POSIX-style TZ's
120
121       Often /etc/localtime is a symlink to the file localtime or to the  cor‐
122       rect timezone file in the system timezone directory.
123

CONFORMING TO

125       SVr4, POSIX.1-2001, 4.3BSD.
126

NOTES

128       Note  that the variable daylight does not indicate that daylight saving
129       time applies right now.  It used to give the number of  some  algorithm
130       (see the variable tz_dsttime in gettimeofday(2)).  It has been obsolete
131       for many years but is required by SUSv2.
132
133       4.3BSD had a function char *timezone(zone, dst) that returned the  name
134       of  the  timezone  corresponding to its first argument (minutes West of
135       GMT).  If the second argument was 0, the standard name was used, other‐
136       wise the daylight saving time version.
137

SEE ALSO

139       date(1), gettimeofday(2), time(2), ctime(3), getenv(3), tzfile(5)
140

COLOPHON

142       This  page  is  part of release 3.22 of the Linux man-pages project.  A
143       description of the project, and information about reporting  bugs,  can
144       be found at http://www.kernel.org/doc/man-pages/.
145
146
147
148                                  2008-08-29                          TZSET(3)
Impressum