_tzset

Description

Sets time environment variables.

#include <time.h> Required only for function declarations  

void _tzset( void );

int _daylight long _timezone char *_tzname[2] Global variables set by function  

Remarks

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 Universal Coordinated Time (UCT) to local time, and by time to compute UCT from system time.

Use the following syntax to set the TZ environment variable:

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

The tzn must be a three-letter time-zone name, such as PST, followed by an optionally signed number, hh, giving the difference in hours between UCT and local time. To specify the exact local time, the hours can be followed by minutes, :mm; seconds, :ss; and a three-letter daylight-saving-time zone, dzn, such as PDT. Separate hours, minutes, and seconds with colons (:). If daylight saving time is never in effect, as is the case in certain states and localities, set TZ without a value for dzn.

If the TZ value is not currently set, the default is PST8PDT, which corresponds to the Pacific time zone.

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

Variable Value

_daylight Nonzero value if a daylight-saving-time zone is specified in the TZ setting; otherwise, 0
_timezone Difference in seconds between GMT and local time
_tzname[0] String value of the three-letter time-zone name from the TZ environmental variable
_tzname[1] String value of the daylight-saving-time zone, or an empty string if the daylight-saving-time zone is omitted from the TZ environmental variable

The default for _daylight is 1; for _timezone, 28,800; for _tzname[0], PST; and for _tzname[1], PDT. This corresponds to “PST8PDT.”

If the DST zone is omitted from the TZ environmental variable, the _daylight variable will be 0 and the _ftime, gmtime, and localtime functions will return 0 for their DST flags.

Return Value

None.

Compatibility

Standards:UNIX

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:DOS32X

Use _tzset for compatibility with ANSI naming conventions of non-ANSI functions. Use tzset and link with OLDNAMES.LIB for UNIX compatibility.

See Also

asctime, _ftime, gmtime, localtime, time

Example

/* TZSET.C: This program first sets up the time zone by placing the variable

* named TZ=EST5 in the environment table. It then uses _tzset to set the

* global variables named _daylight, _timezone, and _tzname.

*/

#include <time.h>

#include <stdlib.h>

#include <stdio.h>

void main( void )

{

if( _putenv( "TZ=EST5EDT" ) == -1 )

{

printf( "Unable to set TZ\n" );

exit( 1 );

}

else

{

_tzset();

printf( "_daylight = %d\n", _daylight );

printf( "_timezone = %ld\n", _timezone );

printf( "_tzname[0] = %s\n", _tzname[0] );

}

exit( 0 );

}

Output

_daylight = 1

_timezone = 18000

_tzname[0] = EST