How To Change TimeZone of Linux

We run CentOS for many of our server builds and this question often comes up. Hope this helps.

Here are the steps:

Assume that your current timezone is UTC as shown below.


Make a backup copy of the default localtime file.

mv /etc/localtime /etc/localtime.bak

Create a symbolic link to a new localtime file

#ln -sf /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
ln -sf /usr/share/zoneinfo/Japan /etc/localtime

Be sure to replace "Japan" with the directory (if your zone has one) and filename of the timezone you want to use. Then test your change by running the command "date" from the command line.

Notes: If you using Amazon EC2, you need prevent Amazon EC2 timezone from reverting back on yum update.

Edit /etc/sysconfig/clock file and set ZONE="America/New_York" (default ZONE="UTC"), EC2 hardware clocks are in UTC so the UTC=true line shouldn't be changed.

#sed -i '/ZONE/c \ZONE="Japan"' /etc/sysconfig/clock
sed -i '/ZONE/c \ZONE="America\/Los_Angeles"' /etc/sysconfig/clock
ln -sf /usr/share/zoneinfo/America/Los_Angeles /etc/localtime

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_Angelesdate
export TZ=Japandate


Popular posts from this blog