Go to the previous, next section.

Specifying the Time Zone with TZ

In the GNU system, a user can specify the time zone by means of the TZ environment variable. For information about how to set environment variables, see section Environment Variables. The functions for accessing the time zone are declared in `time.h'.

The value of the TZ variable can be of one of three formats. The first format is used when there is no Daylight Saving Time (or summer time) in the local time zone:

std offset

The std string specifies the name of the time zone. It must be three or more characters long and must not contain a leading colon or embedded digits, commas, or plus or minus signs. There is no space character separating the time zone name from the offset, so these restrictions are necessary to parse the specification correctly.

The offset specifies the time value one must add to the local time to get a Coordinated Universal Time value. It has syntax like [+|-]hh[:mm[:ss]]. This is positive if the local time zone is west of the Prime Meridian and negative if it is east. The hour must be between 0 and 24, and the minute and seconds between 0 and 59.

For example, here is how we would specify Eastern Standard Time, but without any daylight savings time alternative:

EST+5

The second format is used when there is Daylight Saving Time:

std offset dst [offset],start[/time],end[/time]

The initial std and offset specify the standard time zone, as described above. The dst string and offset specify the name and offset for the corresponding daylight savings time time zone; if the offset is omitted, it defaults to one hour ahead of standard time.

The remainder of the specification describes when daylight savings time is in effect. The start field is when daylight savings time goes into effect and the end field is when the change is made back to standard time. The following formats are recognized for these fields:

Jn
This specifies the Julian day, with n between 1 and 365. February 29 is never counted, even in leap years.

n
This specifies the Julian day, with n between 0 and 365. February 29 is counted in leap years.

Mm.w.d
This specifies day d of week w of month m. The day d must be between 0 (Sunday) and 6. The week w must be between 1 and 5; week 1 is the first week in which day d occurs, and week 5 specifies the last d day in the month. The month m should be between 1 and 12.

The time fields specify when, in the local time currently in effect, the change to the other time occurs. If omitted, the default is 02:00:00.

For example, here is how one would specify the Eastern time zone in the United States, including the appropriate daylight saving time and its dates of applicability. The normal offset from GMT is 5 hours; since this is west of the prime meridian, the sign is positive. Summer time begins on the first Sunday in April at 2:00am, and ends on the last Sunday in October at 2:00am.

EST+5EDT,M4.1.0/M10.5.0

The schedule of daylight savings time in any particular jurisdiction has changed over the years. To be strictly correct, the conversion of dates and times in the past should be based on the schedule that was in effect then. However, the system has no facilities to let you specify how the schedule has changed from year to year. The most you can do is specify one particular schedule--usually the present day schedule--and this is used to convert any date, no matter when.

The third format looks like this:

:characters

Each operating system interprets this format differently; in the GNU C library, characters is the name of a file which describes the time zone.

If the TZ environment variable does not have a value, the operation chooses a time zone by default. Each operating system has its own rules for choosing the default time zone, so there is little we can say about them.

Go to the previous, next section.