Standard C Library (libc.so, libc.a)
extern int daylight; extern long timezone; extern char *tzname;
Interfaces documented on this reference page conform to industry standards as follows:
tzset(): POSIX.1, XPG4, XPG4-UNIX
Refer to the standards(5) reference page for more information about industry standards and associated tags.
The tzset() function uses the value of the environment variable TZ to set time conversion information used by several other functions, including ctime(), ctime_r(), getdate(), getdate_r(), localtime(), localtime_r(), mktime(), strftime(), and strptime().
If the TZ variable is not set, tzset uses implementation-dependent default timezone information. On Tru64 UNIX systems, this information is located in the /etc/zoneinfo/localtime file. See the section, Tru64 UNIX Timezone Handling, for details.
The tzset() function sets the external variable tzname as follows:
tzname = "std";
tzname = "dst";
where std indicates the standard timezone and dst designates the alternative timezone (such as Daylight Savings Time). (These variables are described below in the section, The TZ Environment Variable.)
The tzset() function also sets the external variable daylight to 0 if Daylight Savings Time conversions should never be applied for the time zone in use. Otherwise, daylight is set to a nonzero value.
The external variable timezone is set to the difference, in seconds, between Coordinated Universal Time (UTC) and local standard time. For example:
Tru64 UNIX uses a public-domain timezone-handling package that puts timezone conversion rules in easily accessible and modifiable files. These files are in the directory /etc/zoneinfo/sources. The timezone compiler zic(8) converts these files to a special format described in tzfile(4) and places them in the /etc/zoneinfo directory. This format is readable by the C library functions that handle timezone information.
The tzset() function uses the tzfile-formatted file linked by /etc/zoneinfo/localtime to set the timezone conversion information. The /etc/zoneinfo/localtime link is set during installation to a file in the /etc/zoneinfo directory. For example, in the eastern United States, /etc/zoneinfo/localtime is linked to /etc/zoneinfo/US/Eastern.
If the TZ environment variable is defined, the defined value overrides the timezone information in /etc/zoneinfo/localtime. TZ can be set by a user as a regular environment variable for converting to alternate time zones. See the section, The TZ Environment Variable, for details.
The libc ctime() and localtime() routines return the local time and timezone information. The ctime() routine returns a string that corresponds to the local time; for example, Tue Oct 27 13:35:29 1992.
The localtime() routine returns a pointer to a tm structure (defined in <sys/time.h>) that contains the local time expressed in fields of the tm structure. For timezone information, there are three relevant fields: A flag that is set to 1 if daylight savings time is currently in effect. Otherwise, the flag is set to 0. Seconds east of Greenwich. For example, -18000 means 5 hours west of Greenwich. Abbreviation for the current time zone (for example, EST, PDT, GMT).
The /etc/zoneinfo/localtime link can be changed by the system administrator to any file in the /etc/zoneinfo directory.
For example, to change the default system timezone to Canada's Atlantic time zone, enter the following as superuser:
# ln -s /etc/zoneinfo/Canada/Atlantic /etc/zoneinfo/localtime
Subsequent calls to the timezone-related functions in libc (ctime() and localtime()) use this link for the default timezone information.
If the timezone and daylight savings time information in the /etc/zoneinfo/sources directory is incorrect for your time zone, you can change the information in the source files and then use the zic command to generate a corresponding /etc/zoneinfo file.
A user can override the default timezone information by setting the TZ environment variable as described in the section, The TZ Environment Variable.
When TZ appears in the environment and its value is not a null string, the value has one of three formats:
stdoffset[dst[offset] [,start[/time],end[/time]]] [Digital] If TZ has the single colon format (:), Coordinated Universal Time (UTC) is used.
[Digital] If TZ has the colon-pathname format (:pathname), the characters following the colon specify the pathname of a tzfile(4) format file from which to read the time conversion information. A pathname beginning with a slash (/) represents an absolute pathname; otherwise, the pathname is relative to the system time conversion information directory /etc/zoneinfo.
If TZ does not begin with a colon (:), the components of the string
are as follows:
Three or more characters that are the designation for the standard (std)
or alternative (dst) time zone (such as Daylight Savings Time).
Only std is required. If dst
is not supplied, the alternative time does not
apply to the locale. Upper- and
lower-case letters are explicitly allowed. Any characters, except digits,
a leading colon (:), comma (,), minus (-), plus (+), and ASCII NUL, are
Indicates the value to be added to the local time to arrive at
GMT. The offset has the form:
As an example, the TZ variable value EST5EDT4,M4.1.0,M10.5.0 describes the rule defined in 1987 for the Eastern time zone in the US. EST (Eastern Standard Time) is the designation for standard time, which is 5 hours behind GMT. EDT (Eastern Daylight Time) is the designation for alternative time, which is 4 hours behind GMT. EDT starts on the first Sunday in April and ends on the last Sunday in October. In both cases, since time was not specified, the changes occur at the default time, which is 2:00 A.M. Note that the start and end dates did not need to be specified since they are the defaults.
[Digital] For users of the SVID2 habitat, TZ is defined by default in the following
std offset [dst[offset] ] [Digital] For users of the SVID3 habitat, TZ is defined by default in the following format:
:pathname See the section, The TZ Environment Variable, for definitions of the parameters used in these formats.
Functions: ctime(3), ctime_r(3), difftime(3), getdate(3), getdate_r(3), getenv(3), localtime(3), localtime_r(3), mktime(3), strftime(3), strptime(3), time(3)
Commands: date(1), zdump(8), zic(8)
Standards: standards(5) delim off