How does defining a time zone in a TZ variable works?

Solution Verified - Updated -

Issue

The following code which sets TZ variable to two different timezones and prints timezone names and offset:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main( void )
{
    setenv("TZ", "MST-10MDT", 1);
    tzset();
    printf("%s %s offset: %d\n", tzname[0], tzname[1], timezone);

    setenv("TZ", "US/Eastern", 1);
    tzset();
    printf("%s %s offset: %d\n", tzname[0], tzname[1], timezone);
}

outputs strange result as if the same timezone was used:

# ./tzset 
MST MDT offset: -36000
MST MDT offset: -36000

Environment

Red Hat Enterprise Linux 5
Red Hat Enterprise Linux 6

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content