Howto: Linux server change or setup the timezone

by Vivek Gite · 20 comments

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

Featured Articles:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 20 comments… read them below or add one }

1 vijay 12.20.06 at 8:19 am

Great Info

2 Lars 11.19.07 at 6:51 am

On Ubuntu you can do

tzconfig

to select and set the time zone.
(tzconfig copies the right time zone file from /usr/share/zoneinfo to /etc/localtime and puts the name of the timezone into /etc/timezone)

3 Rich 06.18.08 at 9:52 pm

Counterintuitively, you should not symlink, only ever copy timezone data files. This is because some programs might attempt to alter /etc/localtime. Before you make a change, notice that /etc/localtime is a regular file.

4 Andy Bach 11.03.08 at 7:45 pm

Note – you’re missing an ‘e’ on the end of:
Create a symlink to file localtime:
# ln -sf /usr/share/zoneinfo/EST localtim

a

5 vivek 11.04.08 at 7:34 am

Andy,

Thanks for pointing out a typo. The faq has been updated.

6 Ral 11.04.08 at 6:24 pm

I don’t get to change the TZ. I cann’t install the tzconfig. I have Ubuntu 8.04. What is wrong ?

7 php trivandrum 11.10.08 at 1:52 am

Hey.. thanks.. it saved my life..

8 am 12.02.08 at 9:33 am

[root@ps2844 ~]# date
Tue Dec 2 10:19:11 UTC 2008

Using the “setup” command, I selected timezone as Asia/Calcutta, and did not check the UTC box. But the time zone does not change.

[root@ps2844 ~]# setup
[root@ps2844 ~]# date
Tue Dec 2 10:20:26 UTC 2008

Also, I did the sym-link for localtime, but without help.

[root@ps2844 ~]# ls -l /etc/localtime
lrwxrwxrwx 1 root root 33 Dec 2 10:16 /etc/localtime -> /usr/share/zoneinfo/Asia/Calcutta

9 R.H. Hartman 01.08.09 at 1:11 pm

On CentOS5, the command is system-config-date. Likely on CentOS4 and earlier as well. Probably related to removing all branding from the upstream vendor’s sources.

10 yemurai 02.20.09 at 4:26 am

Thanks! (system-config-date) That worked.

11 adityo 04.30.09 at 5:23 am

use tzselect for ubuntu gutsy

12 MANOJ PARMAR 06.03.09 at 2:43 am

1.Iam having a linux virtual machine running apache server in RHEL4.4. Iam facing a problem that everyday in the morning I had to change its date and time . It is always running 12hrs back.

13 MANOJ PARMAR 06.03.09 at 2:48 am

1. iam also facing problem in RHJEL 5.2 virtualization. Iam having one host machine installed with RHEL 5.2. Iam also running 03 Server Virtually on it. But via network i can access virtual machine but not the host machine. Many tinme I had to restart the network service but after some time the problem exist. The service is also put under chkconfig.

2. Iam having a linux virtual machine running apache server in RHEL4.4. Iam facing a problem that everyday in the morning I had to change its date and time . It is always running 12hrs back.

14 Mark Finch 06.20.09 at 1:23 pm

Thanks a lot. This really helped me.

15 Andreas 07.01.09 at 8:38 am

On CactiEZ 0.6 (based on CentOS) the command is ‘tzselect’ too.
No more system-config-date or ‘config’

cheers

16 Irisha Stacy 08.20.09 at 11:35 pm

Slackware dudes, use tzselect;

Or simply create a symbolic link called

/etc/localtime

from the suitable zones resides in /usr/share/zone

God bless god,

17 Kamal 09.18.09 at 6:56 am

Thanks buddy, it helped me a lot!!

18 Jan 10.31.09 at 9:01 pm

Does anybody know what can be done on SUSE if this does not work for some TZ? UTC works for example, but setting to Europe/Berlin or GB does not. These give back an empty value when using

date +%Z

19 Justin 11.04.09 at 9:54 pm

RHEL 5 is also using tzselect as the command name.

20 Martin 01.05.10 at 1:34 am

OH MY GAD! Thank you for this article. I searched a long time to find this solution that finally worked. I use proxmox and this was the only thing that did it.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous FAQ:

Next FAQ:

nixCraft FAQ PDF Collection Now Available To All