Wednesday, March 11, 2009

How To Set Time Zone (TZ) Correctly in a Unix/Solaris System?

First, check your environ manual:

> man -s5 environ
...
TZ

Timezone information. The contents of this environment
variable are used by the functions ctime(3C),
localtime(3C), strftime(3C), and mktime(3C) to override
the default timezone. The value of TZ has one of the two
formats (spaces inserted for clarity):

:characters

or

std offset dst offset, rule

If TZ is of the first format (that is, if the first
character is a colon (:)), or if TZ is not of the second
format, then TZ designates a path to a timezone database
file relative to /usr/share/lib/zoneinfo/
, ignoring a
leading colon if one exists.
...

Second, check is your city is under /usr/share/lib/zoneinfo.


csdbld03: zoneinfo> find . -name Kuala_Lumpur
./Asia/Kuala_Lumpur

Third, update TZ at your /etc/TIMEZONE. Example TZ=Asia/Kuala_Lumpur.

Avoid to use GMT[+/-] format as it is obsolete.
> cat /usr/share/lib/zoneinfo/src/README
...
The following files have been removed from the release:

/usr/share/lib/zoneinfo/GMT-12
/usr/share/lib/zoneinfo/GMT-11
/usr/share/lib/zoneinfo/GMT-10
/usr/share/lib/zoneinfo/GMT-9
/usr/share/lib/zoneinfo/GMT-8
/usr/share/lib/zoneinfo/GMT-7
/usr/share/lib/zoneinfo/GMT-6
/usr/share/lib/zoneinfo/GMT-5
/usr/share/lib/zoneinfo/GMT-4
/usr/share/lib/zoneinfo/GMT-3
/usr/share/lib/zoneinfo/GMT-2
/usr/share/lib/zoneinfo/GMT-1
/usr/share/lib/zoneinfo/GMT+1
/usr/share/lib/zoneinfo/GMT+2
/usr/share/lib/zoneinfo/GMT+3
/usr/share/lib/zoneinfo/GMT+4
/usr/share/lib/zoneinfo/GMT+5
/usr/share/lib/zoneinfo/GMT+6
/usr/share/lib/zoneinfo/GMT+7
/usr/share/lib/zoneinfo/GMT+8
/usr/share/lib/zoneinfo/GMT+9
/usr/share/lib/zoneinfo/GMT+10
/usr/share/lib/zoneinfo/GMT+11
/usr/share/lib/zoneinfo/GMT+12
/usr/share/lib/zoneinfo/GMT+13
...