#include <time.h> void tzset(void);
tzset
accesses the environment variable TZ
, and uses it
to define time-zone information for the other timing functions
(ctime
, localtime
, strftime
, and mktime
).
If TZ
is not defined, the default time zone is
implementation defined (see Timing Functions ).
See Timing Functions for the expected format of the TZ
environment variable.
In addition to saving time-zone information for the other timing
functions, tzset
stores time-zone names in the external array
tzname
, declared in <time.h>
as:
extern char *tzname[2];
tzname[0]
is set by tzset
to the name of the standard time
zone, and tzname[1]
is set to the name of the daylight savings
time zone.
Note:
The localtime
, ctime
, strftime
, and mktime
functions call tzset
themselves during processing. Therefore, you
ordinarily do not have to call it yourself.
Note:
The prototype for tzset
in <time.h>
is not visible unless
_SASC_POSIX_SOURCE
or another POSIX feature test macro is defined
before <time.h>
is included.
tzset
.
tzname
can be accessed only in the main load
module of an application. In other load modules, this information can be
accessed by calling the function _tzname()
.
TZ
environment variable to Pacific Standard
Time and Pacific Daylight Time:
#include <stdlib.h> #include <time.h> #include <stdio.h> #define _SASC_POSIX_SOURCE1 main() { time_t timeval; setenv("TZ","PST8PDT"); tzset(); time(&timeval); /* Print the current Pacific time. */ printf("The current Pacific time and date are: %s", ctime(&timeval)); }
ctime
, localtime
, mktime
, strftime
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.