Réduire la table des matières
Développer la table des matières
Important Il est possible que le présent document ne corresponde pas aux pratiques recommandées pour le développement actuel. Par ailleurs, il se peut que des liens de téléchargement et d'autres ressources ne soient plus valides. La version recommandée actuelle est disponible ici. ArchiveDisclaimer


Sets time environment variables.

void _tzset( void );

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]


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


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


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


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


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' 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:


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. In the Windows operating system , this information is specified in the Date/Time application in Control Panel. 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


Nonzero value if a daylight-saving-time zone is specified in TZ setting; otherwise, 0



Difference in seconds between UTC and local time.

28800 (28800 seconds equals 8 hours)


String value of time-zone name from TZ environmental variable; empty if TZ has not been set



String value of daylight-saving-time zone; empty if daylight-saving-time zone is omitted from TZ environmental variable


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.

Routine Required header Compatibility



Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

For additional compatibility information, see Compatibility in the Introduction.

// crt_tzset.cpp
// 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>

int main( void )
   if( _putenv_s( "TZ", "EST5EDT" ) != 0 )
      printf( "Unable to set TZ\n" );
      exit( 1 );
      int daylight;
      _get_daylight( &daylight );
      printf( "_daylight = %d\n", daylight );
      long timezone;
      _get_timezone( &timezone );
      printf( "_timezone = %ld\n", timezone );
      size_t s;
      char tzname[100];
      _get_tzname( &s, tzname, sizeof(tzname), 0 );
      printf( "_tzname[0] = %s\n", tzname );
   exit( 0 );


_daylight = 1
_timezone = 18000
_tzname[0] = EST

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

© 2016 Microsoft