The time in a Linux/Unix system is the amount of seconds since midnight UTC on January 1, 1970. This does not include leap seconds.
You can change the timezone in different versions of Linux/Unix. I will show you how to do this later in this HowTo, but here is the universal method.
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.