Syntax
#include <time.h> void tzset(void);Description
tzset uses the environment variable TZ to change the time zone and daylight saving time (DST) zone values. These values are used by the gmtime and localtime functions to make corrections from Coordinated Universal Time (formerly GMT) to local time.
To use tzset, set the TZ variable to the appropriate values. (For the possible values for TZ, see the chapter on run-time environment variables in the VisualAge C++ Programming Guide.) Then call tzset to incorporate the changes in the time zone information into your current locale.
To set TZ from within a program, use putenv before calling tzset.
Note: The time and date functions begin at 00:00:00 Coordinated Universal Time, January 1, 1970.
There is no return value.
This example uses putenv and tzset to set the time zone to Central Time.
#include <time.h> #include <stdio.h> int main(void) { time_t currentTime; struct tm *ts; /* Get the current time */ (void)time(¤tTime); printf("The GMT time is %s", asctime(gmtime(¤tTime))); ts = localtime(¤tTime); if (ts->tm_isdst > 0) /* check if Daylight Saving Time is in effect */ { printf("The local time is %s", asctime(ts)); printf("Daylight Saving Time is in effect.\n"); } else { printf("The local time is %s", asctime(ts)); printf("Daylight Saving Time is not in effect.\n"); } printf("**** Changing to Central Time ****\n"); putenv("TZ=CST6CDT"); tzset(); ts = localtime(¤tTime); if (ts->tm_isdst > 0) /* check if Daylight Saving Time is in effect */ { printf("The local time is %s", asctime(ts)); printf("Daylight Saving Time is in effect.\n"); } else { printf("The local time is %s", asctime(ts)); printf("Daylight Saving Time is not in effect.\n"); } return 0; /**************************************************************************** The output should be similar to: The GMT time is Fri Jan 13 21:49:26 1995 The local time is Fri Jan 13 16:49:26 1995 Daylight Saving Time is not in effect. **** Changing to Central Time **** The local time is Fri Jan 13 15:49:26 1995 Daylight Saving Time is not in effect. ****************************************************************************/ }
Related Information