In a linux/unix system, the time is the number of seconds elapsed since midnight UTC on the morning of January 1, 1970, not counting leap seconds.

There are different ways and procedures to change timezones in different flavors of linux/unix (which i will explain later in this HowTo) but universal procedure to do it in all flavors is explained below:

Using /etc/localtime to set timezone:

This is the file which sets the timezone of your system. Usually it is the symbolic link to the original file of the timezone which are all stored in “/usr/share/zoneinfo/”.

To change the timezone with this file follow this procedure:

 # cd /etc/

If you wish, backup the previous timezone configuration by copying it to a different location. Such as

 # cp /etc/localtime  /etc/localtime-old

Browse through the timezones given in “/usr/share/zoneinfo/” and finalize which one you would like to use. Then create a symlink of that timezone on the “/etc/” directory with name “localtime

 # ln -sf /usr/share/zoneinfo/dir/zonefile localtime

For ex: if you want it to set to IST (Indian standard time) then use this command

 # ln -sf /usr/share/zoneinfo/Asia/Calcutta locatime

You can verify the same using “date” command

 # date
Wed Feb 24 22:50:50 IST 2010

If you have the utility “rdate“, update the current system time by executing

 # /usr/bin/rdate -s time-a.nist.gov

Now set the ZONE entry in the file “/etc/sysconfig/clock” file (e.g. “Asia/Calcutta”, the ZONE parameter is only evaluated by system-config-date)

After doing all this, remember to sync the hardware clock with your new timezone setting, This can be done by executing following command:

 # /sbin/hwclock --systohc

This is something by which you can change the timezone on the system level. But if you want to change a timezone to test some script, you can do it by changing your environment variable in your shell.

 # export TZ=Asia/Calcutta

Remember, that in the above case, the timezone will only be changed for the same shell and will be temporary, means as soon as you logout of the shell, all you setting will be gone.

For different flavors of linux/unix you can use different commands if you don’t want to follow the above procedure:

  • Redhat: “redhat-config-date” will open a dialog box –> follow the instructions.
  • Centos/fedora: “system-config-date” will open a dialog box –> follow the instructions.
  • Slackware/Freebsd: “tzselect” will open a dialog box –> follow the instructions.
  • Ubuntu: “dpkg-reconfigure tzdata” OR “tzconfig” will open a dialog box –> follow the instructions.

In most of the above cases you will get an interface something like this.

Move to the timezone you would like to change and the simply press “OK”. This will change the timezone of your system.

Change Timezone on Linux Cellphones:

On mobile phones and other small devices that run Linux, the time zone is stored in /etc/TZ. So we need to follow the same procedure to change the timezone on cellphones and other small devices running on linux.

To setup UTC: To setup UTC timezone you need to do a simple step. Mark “UTC=true” in “/etc/sysconfig/clock” file.

 # vi /etc/sysconfig/clock and change the UTC line to: "UTC=true"

If you enjoyed this post, make sure you subscribe to my RSS feed!!!!