Monday, July 25, 2016

Set timezone using /etc/localtime configuration file

Generic procedure to change timezone under Linux
Cd to /etc, run:

# 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 note 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.
How do I verify new settings?
Use the date command to verify that your timezone is changed:

$ date

Output:
Tue Aug 27 14:46:08 EST 2006
How do I use of environment variable called TZ?

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:

Post a Comment