Home

tzset

tzset is a C standard library function that initializes the program’s time zone information from the environment. It reads the TZ environment variable (if set) and updates global variables used by time-related functions such as localtime and mktime. After a call to tzset, these functions will interpret times according to the configured local time zone and daylight saving rules.

Prototype and scope: The function is declared in time.h as void tzset(void). It affects global state for

TZ environment variable and formats: tzset reads TZ to determine the local time zone. If TZ is

Portability and related functions: tzset is available on POSIX-compliant systems and, on Windows, a variant named

the
process,
including
the
tzname
array
(which
holds
the
standard
and
daylight
names),
the
timezone
offset
from
UTC,
and
the
daylight
flag.
Because
it
alters
global
state,
tzset
is
generally
not
considered
thread-safe
in
all
C
library
implementations;
repeated
or
concurrent
calls
can
lead
to
race
conditions
in
multi-threaded
programs
unless
proper
synchronization
is
used.
unset
or
empty,
the
system
default
is
used.
The
TZ
value
is
interpreted
using
a
POSIX-style
format
describing
standard
time,
offset
from
UTC,
and
optional
daylight
saving
rules.
In
many
implementations,
TZ
can
also
take
a
path-style
form
beginning
with
a
colon,
followed
by
a
zone
description
file
path
from
the
zoneinfo
database
(for
example,
TZ=:/usr/share/zoneinfo/America/New_York).
Examples
of
simple
forms
include
EST5EDT
or
PST8PDT,
while
more
explicit
forms
may
specify
start
and
end
rules
for
DST.
_tzset
may
be
provided
by
the
C
runtime.
It
relates
to
functions
such
as
localtime,
gmtime,
and
mktime,
which
rely
on
the
configured
time
zone.
For
modern
code
requiring
locale-aware
time
data,
consider
using
established
time
zone
databases
and
safe,
thread-aware
approaches
where
possible.