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 of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.