[Chapter 6] 6.6 The TZ Environment Variable
Author: Jerry Peek, Tim O'Reilly & Mike Loukides
Date: 1998-10-23T15:38:04Z

#

| Chapter 6 Shell and Environment Variables |

## 6.6 The TZ Environment Variable

The TZ environment variable is a little obscure, but it can be very useful. It tells UNIX what time zone you're in. The default time zone was set when your system was first installed (and we'll assume it was done correctly). However, there are lots of times when you want to change your time zone temporarily. For example, you might be connected via a communications program to a UNIX system in another time zone; its notion of the correct time is right for its location, but not for your location. Or you may move your system to another location; you need to change the time zone, but you don't want to reinstall the software (which can be painful). Article 6.7 shows how to use TZ to check the time in another zone.

To set TZ, give a command like:

>     % setenv TZ timezone                      C shell

>     $ TZ=timezone; export TZ                  Bourne shell

This setting takes effect immediately; if you give the date (51.10) command, you'll see the current time in your new zone.

The time zones are, basically, files in the directory /usr/lib/zoneinfo or its subdirectories. You'll have to look through there to see what's available - but a lot is available, including all the time zones in the United States, Canada, Australia, most of Europe, and a lot of Asia, Africa, and South America. A lot of "oddball" time zones are included: for example, the state of Indiana, large parts of which don't observe Daylight Savings Time, and Michigan, for reasons that are completely unclear to me.

So, let's say you want to set the current time so that it's correct in Wyoming. You look in /usr/lib/zoneinfo and see a directory named US. You then look in the US directory, and see a file named Mountain. So your time zone setting is US/Mountain:

>     % setenv TZ US/Mountain
>     % date
>     Wed Mar  6 19:34:53 MST 1996

You don't have to worry about the difference between daylight and standard time, or the fact that Daylight Savings Time rules aren't the same everywhere. That information is all encoded in the zonefiles database.

- ML

6.5 PATH and path |  | 6.7 What Time Is It in Japan?