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():
21           _POSIX_C_SOURCE
22
23       tzname:
24           _POSIX_C_SOURCE
25
26       timezone, daylight:
27           _XOPEN_SOURCE
28               || /* Glibc since 2.19: */ _DEFAULT_SOURCE
29               || /* Glibc <= 2.19: */ _SVID_SOURCE
30

DESCRIPTION

32       The tzset() function initializes the tzname variable from the TZ  envi‐
33       ronment  variable.   This function is automatically called by the other
34       time conversion functions that depend on the timezone.  In a  System-V-
35       like environment, it will also set the variables timezone (seconds West
36       of UTC) and daylight (to 0 if this timezone does not have any  daylight
37       saving  time rules, or to nonzero if there is a time, past, present, or
38       future when daylight saving time applies).
39
40       If the TZ variable does not appear in the environment, the system time‐
41       zone  is  used.  The system timezone is configured by copying, or link‐
42       ing, a file in the tzfile(5)  format  to  /etc/localtime.   A  timezone
43       database of these files may be located in the system timezone directory
44       (see the FILES section below).
45
46       If the TZ variable does appear in the environment,  but  its  value  is
47       empty,  or  its  value  cannot  be interpreted using any of the formats
48       specified below, then Coordinated Universal Time (UTC) is used.
49
50       The value of TZ can be one of two  formats.   The  first  format  is  a
51       string of characters that directly represent the timezone to be used:
52
53           std offset[dst[offset][,start[/time],end[/time]]]
54
55       There  are no spaces in the specification.  The std string specifies an
56       abbreviation for the timezone and must  be  three  or  more  alphabetic
57       characters.   When  enclosed between the less-than (<) and greater-than
58       (>) signs, the characters set is expanded to include the plus (+) sign,
59       the  minus (-) sign, and digits.  The offset string immediately follows
60       std and specifies the time value to be added to the local time  to  get
61       Coordinated  Universal Time (UTC).  The offset is positive if the local
62       timezone is west of the Prime Meridian and negative if it is east.  The
63       hour must be between 0 and 24, and the minutes and seconds 00 and 59:
64
65           [+|-]hh[:mm[:ss]]
66
67       The  dst  string  and offset specify the name and offset for the corre‐
68       sponding daylight saving timezone.  If the offset is  omitted,  it  de‐
69       faults to one hour ahead of standard time.
70
71       The  start  field  specifies when daylight saving time goes into effect
72       and the end field specifies when the change is made  back  to  standard
73       time.  These fields may have the following formats:
74
75       Jn     This  specifies  the  Julian day with n between 1 and 365.  Leap
76              days are not counted.  In this format, February 29 can't be rep‐
77              resented; February 28 is day 59, and March 1 is always day 60.
78
79       n      This  specifies  the  zero-based Julian day with n between 0 and
80              365.  February 29 is counted in leap years.
81
82       Mm.w.d This specifies day d (0 <= d <= 6) of week w (1 <= w  <=  5)  of
83              month m (1 <= m <= 12).  Week 1 is the first week in which day d
84              occurs and week 5 is the last week in which day d occurs.  Day 0
85              is a Sunday.
86
87       The  time  fields  specify when, in the local time currently in effect,
88       the change to the other  time  occurs.   If  omitted,  the  default  is
89       02:00:00.
90
91       Here  is  an example for New Zealand, where the standard time (NZST) is
92       12 hours ahead of UTC, and daylight saving time (NZDT), 13 hours  ahead
93       of  UTC,  runs  from the first Sunday in October to the third Sunday in
94       March, and the changeovers happen at the default time of 02:00:00:
95
96           TZ="NZST-12:00:00NZDT-13:00:00,M10.1.0,M3.3.0"
97
98       The second format specifies that the  timezone  information  should  be
99       read from a file:
100
101           :[filespec]
102
103       If  the  file specification filespec is omitted, or its value cannot be
104       interpreted, then Coordinated Universal Time (UTC) is used.   If  file‐
105       spec  is  given, it specifies another tzfile(5)-format file to read the
106       timezone information from.  If filespec does not begin with a '/',  the
107       file  specification  is  relative to the system timezone directory.  If
108       the colon is omitted each of the above TZ formats will be tried.
109
110       Here's an example, once more for New Zealand:
111
112           TZ=":Pacific/Auckland"
113

ENVIRONMENT

115       TZ     If this variable is set its value takes precedence over the sys‐
116              tem configured timezone.
117
118       TZDIR  If this variable is set its value takes precedence over the sys‐
119              tem configured timezone database directory path.
120

FILES

122       /etc/localtime
123              The system timezone file.
124
125       /usr/share/zoneinfo/
126              The system timezone database directory.
127
128       /usr/share/zoneinfo/posixrules
129              When a TZ string includes a dst timezone without  anything  fol‐
130              lowing  it,  then this file is used for the start/end rules.  It
131              is in the tzfile(5) format.  By default, the  zoneinfo  Makefile
132              hard links it to the America/New_York tzfile.
133
134       Above  are  the  current  standard file locations, but they are config‐
135       urable when glibc is compiled.
136

ATTRIBUTES

138       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
139       tributes(7).
140
141       ┌─────────────────────────────────┬───────────────┬────────────────────┐
142Interface                        Attribute     Value              
143       ├─────────────────────────────────┼───────────────┼────────────────────┤
144tzset()                          │ Thread safety │ MT-Safe env locale │
145       └─────────────────────────────────┴───────────────┴────────────────────┘
146

CONFORMING TO

148       POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
149

NOTES

151       4.3BSD  had a function char *timezone(zone, dst) that returned the name
152       of the timezone corresponding to its first argument  (minutes  West  of
153       UTC).  If the second argument was 0, the standard name was used, other‐
154       wise the daylight saving time version.
155

SEE ALSO

157       date(1), gettimeofday(2), time(2), ctime(3), getenv(3), tzfile(5)
158

COLOPHON

160       This page is part of release 5.13 of the Linux  man-pages  project.   A
161       description  of  the project, information about reporting bugs, and the
162       latest    version    of    this    page,    can     be     found     at
163       https://www.kernel.org/doc/man-pages/.
164
165
166
167                                  2021-03-22                          TZSET(3)
Impressum