![]() |
![]() |
![]() |
![]() |
Set the time according to the TZ environment variable
#include <time.h> void tzset( void );
libc
The tzset() function sets the global variables daylight, timezone and tzname according to the value of the TZ environment variable.
The global variables have the following values after tzset() is executed:
The time that you set on the computer with the date command reflects Coordinated Universal Time (UTC). The environment variable TZ is used to establish the local time zone. See the "The TZ environment variable" in the Global Data and the TZ Environment Variable chapter for a discussion of how to set the time zone.
#include <stdio.h> #include <stdlib.h> #include <time.h> void print_zone() { char *tz; printf( "TZ: %s\n", (tz = getenv( "TZ" )) ? tz : "default EST5EDT" ); printf( " daylight: %d\n", daylight ); printf( " timezone: %ld\n", timezone ); printf( " time zone names: %s %s\n", tzname[0], tzname[1] ); } int main( void ) { print_zone(); setenv( "TZ", "PST8PDT", 1 ); tzset(); print_zone(); return EXIT_SUCCESS; }
produces the output:
TZ: default EST5EDT daylight: 1 timezone: 18000 time zone names: EST EDT TZ: PST8PDT daylight: 1 timezone: 28800 time zone names: PST PDT
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |
ctime(), localtime(), localtime_r(), mktime(), strftime()
![]() |
![]() |
![]() |
![]() |