Thursday, July 12, 2012

Howto: Linux server change or setup the timezone

Source: http://www.cyberciti.biz/faq/howto-linux-unix-change-setup-timezone-tz-variable/
Q. My timezone is pointing to wrong timezone. How do I setup or change the timezone under Linux operating systems?

A. Unix time, or POSIX time, is a system for describing points in time: it is the number of seconds elapsed since midnight UTC on the morning of January 1, 1970, not counting leap seconds.
The definition for time zones can be written in short form as UTC±n (or GMT±n), where n is the offset in hours.

Change Linux timezone

Select the method as per your Linux distribution:

If you are using Fedora / RHEL / Cent OS Linux

Type the redhat-config-date command at the command line to start the time and date properties tool.
# redhat-config-date
OR type setup and select time zone configuration (good for remote ssh text based Linux server sessiob)
# setup
Select timezone configuration
Fig.01: Redhat / CentOS Server Setting Up Timezone
Fig.01: Redhat / CentOS Server Setting Up Timezone
Now, just follow on screen instructions to change timezone.

Set timezone using /etc/localtime configuration file [any Linux distro]

Often /etc/localtime is a symlink to the file localtime or to the correct time zone file in the system time zone directory.

Generic procedure to change timezone

Change directory to /etc
# cd /etc
Create a symlink to file localtime:
# ln -sf /usr/share/zoneinfo/EST localtime
OR some distro use /usr/share/zoneinfo/dirname/zonefile format (Red hat and friends)
# ln -sf /usr/share/zoneinfo/EST localtime
OR if you want to set up it to IST (Asia/Calcutta):
# ln -sf /usr/share/zoneinfo/Asia/Calcutta localtime
Please mote that in above example you need to use directory structure i.e. if you want to set the timezone to Calcutta (India) which is located in the Asia directory you will then have to setup using as above.
Use date command to verify that your timezone is changed:
$ date
Output:
Tue Aug 27 14:46:08 EST 2006

Use of environment variable

You can use TZ environment variable to display date and time according to your timezone:
$ export TZ=America/Los_Angeles
$ date

Sample Output:
Thu Aug 27 11:10:08 PST 2006

No comments: