2.1.8.42 _tzset


Description

Uses the current setting of the environment variable TZ to update time settings.

Syntax

void _tzset( void )

Parameters

Return

Examples

EX1

void _tzset_ex1()
{
    _tzset();
    int daylight;
    long timezone;
    char* tzname[2];
    get_time_setting(&daylight, &timezone, tzname);
    printf( "daylight = %d\n", daylight );
    printf( "timezone = %ld\n", timezone );
    printf( "tzname[0] = %s\n", tzname[0] );
}

Remark

The _tzset function uses the current setting of the environment variable TZ to assign values to three global variables: _daylight, _timezone, and _tzname.

These variables are used by the _ftime and localtime functions to make corrections from coordinated universal time (UTC) to local time, and by the time function to compute UTC from system time. Use the following syntax to set the TZ environment variable:


set TZ=tzn[+ | -]hh[:mm[:ss] ][dzn]

tzn

Three-letter time-zone name, such as PST. You must specify the correct offset from local time to UTC.

hh

Difference in hours between UTC and local time. Optionally signed.

mm

Minutes. Separated from hh by a colon (:).

ss

Seconds. Separated from mm by a colon (:).

dzn

Three-letter daylight-saving-time zone such as PDT. If daylight saving time is never in effect in the locality, set TZ without a value for dzn. The C run-time library assumes the United States's rules for implementing the calculation of Daylight Saving Time (DST).


For example, to set the TZ environment variable to correspond to the current time zone in Germany, you can use one of the following statements:


set TZ=GST-1GDT

set TZ=GST+1GDT


These strings use GST to indicate German standard time, assume that Germany is one hour ahead of UTC, and assume that daylight savings time is in effect.


If the TZ value is not set, _tzset attempts to use the time zone information specified by the operating system. Under Windows NT and Windows 95, this information is specified in the Control Panel's Date/Time application. If _tzset cannot obtain this information, it uses PST8PDT by default, which signifies the Pacific time zone.


Based on the TZ environment variable value, the following values are assigned to the global variables _daylight, _timezone, and _tzname when _tzset is called:


Global Variable Description Default Value
_daylight Nonzero value if a daylight-saving-time zone is specified in TZ setting; otherwise, 0 1


_timezone Difference in seconds between UTC and local time. 28800 (28800 seconds equals 8 hours)
_tzname[0] String value of time-zone name from TZ environmental variable; empty if TZ has not been set PST
_tzname[1] String value of daylight-saving-time zone; empty if daylight-saving-time zone is omitted from TZ environmental variable PDT

The default values shown in the preceding table for _daylight and the _tzname array correspond to "PST8PDT". If the DST zone is omitted from the TZ environmental variable, the value of _daylight is 0 and the _ftime, gmtime, and localtime functions return 0 for their DST flags.

See Also

Header to Include

origin.h

Reference