1tzset(3)                   Library Functions Manual                   tzset(3)
2
3
4

NAME

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

LIBRARY

10       Standard C library (libc, -lc)
11

SYNOPSIS

13       #include <time.h>
14
15       void tzset(void);
16
17       extern char *tzname[2];
18       extern long timezone;
19       extern int daylight;
20
21   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
22
23       tzset():
24           _POSIX_C_SOURCE
25
26       tzname:
27           _POSIX_C_SOURCE
28
29       timezone, daylight:
30           _XOPEN_SOURCE
31               || /* glibc >= 2.19: */ _DEFAULT_SOURCE
32               || /* glibc <= 2.19: */ _SVID_SOURCE
33

DESCRIPTION

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

ENVIRONMENT

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

FILES

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

ATTRIBUTES

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

STANDARDS

151       POSIX.1-2008.
152

HISTORY

154       POSIX.1-2001, SVr4, 4.3BSD.
155
156       4.3BSD  had a function char *timezone(zone, dst) that returned the name
157       of the timezone corresponding to its first argument  (minutes  West  of
158       UTC).  If the second argument was 0, the standard name was used, other‐
159       wise the daylight saving time version.
160

SEE ALSO

162       date(1), gettimeofday(2), time(2), ctime(3), getenv(3), tzfile(5)
163
164
165
166Linux man-pages 6.04              2023-03-30                          tzset(3)
Impressum