Chapter Contents

Previous

Next
tzset

tzset



Specify Time Zone

Portability: POSIX.1 conforming


SYNOPSIS
DESCRIPTION
RETURN VALUE
CAUTION
EXAMPLE
RELATED FUNCTIONS
SEE ALSO


SYNOPSIS

#include <time.h>

void tzset(void);


DESCRIPTION

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.  [cautionend]

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.  [cautionend]


RETURN VALUE

There is no return value for tzset .


CAUTION

The external variable 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() .


EXAMPLE

This example sets the 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));
}


RELATED FUNCTIONS

ctime , localtime , mktime , strftime


SEE ALSO


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.