Howto: Linux server change or setup the timezone

by Vivek Gite on August 27, 2006 · 43 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:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 43 comments… read them below or add one }

1 vijay December 20, 2006

Great Info

Reply

2 Lars November 19, 2007

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)

Reply

3 Rich June 18, 2008

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.

Reply

4 Andy Bach November 3, 2008

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

a

Reply

5 vivek November 4, 2008

Andy,

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

Reply

6 Ral November 4, 2008

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

Reply

7 php trivandrum November 10, 2008

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

Reply

8 am December 2, 2008

[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

Reply

9 R.H. Hartman January 8, 2009

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.

Reply

10 yemurai February 20, 2009

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

Reply

11 adityo April 30, 2009

use tzselect for ubuntu gutsy

Reply

12 MANOJ PARMAR June 3, 2009

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.

Reply

13 Nate Cummings January 17, 2012

Use an NTP cronjob to update your time

Reply

14 MANOJ PARMAR June 3, 2009

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.

Reply

15 Mark Finch June 20, 2009

Thanks a lot. This really helped me.

Reply

16 Andreas July 1, 2009

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

cheers

Reply

17 Irisha Stacy August 20, 2009

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,

Reply

18 Kamal September 18, 2009

Thanks buddy, it helped me a lot!!

Reply

19 Jan October 31, 2009

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

Reply

20 Justin November 4, 2009

RHEL 5 is also using tzselect as the command name.

Reply

21 Martin January 5, 2010

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.

Reply

22 devkumar March 28, 2010

Thanks budy ,
I have same issue which has been resolved with help of you guys

Reply

23 syed khalid April 4, 2010

Hai…
My Hp-ux server showing wrong time …so how can i change it…
hp-ux server:HP-UX B.11.11 U 9000/800 941485843 unlimited-user license
and if i change hp-ux server is it change in oracle database also..

Reply

24 Chandan April 23, 2010

Hello,

How to change the TimeZone of the server based in London but it has same TZ as Paris.
We have Linux server.
Using command line and which files to be modified.

Can any one help me out for the above.

Reply

25 Adam Monsen July 8, 2010

FYI, on Ubuntu 10.04, I also thought it was necessary to manually maintain /etc/localtime, /etc/timezone and friends to change to Asia/Calcutta. But I noticed when running “dpkg-reconfigure tzdata” that Asia/Kolkata does show up, and this is the same city/timezone. redhat-config-date might do something similar, I don’t know.

/usr/share/zoneinfo/Asia/Calcutta and /usr/share/zoneinfo/Asia/Kolkata point to the same inode on my system.

Reply

26 Mohamed Yusuf July 28, 2010

It works. Thanks a lot.

Reply

27 Hariharan Madhavan July 31, 2010

Thanks a bunch. I found this extremely useful to set my Server time to Indian TimeZone.

Reply

28 yogesh August 23, 2010

It worked thanks a lot

Reply

29 Luis September 24, 2010

using fedora… “rm /etc/localtime” first and then make the link , worked for me.

Now amsn works fine and my local time now its right.

thx a lot.

Reply

30 Jane January 19, 2011

I mistakenly typed in date -u now it always shows date in UTC time, everytime I type date. I want the date to revert back to showing PST time when I type date.
How do I revert back for date to just PST time agan.

Reply

31 Hugo January 20, 2011

Don’t use “system-config-date” if you have build the symbolic link like

[root zoneinfo]# ls -l /etc/localtime
lrwxrwxrwx 1 root root 23 Jan 20 13:43 /etc/localtime -> /usr/share/zoneinfo/GMT

It could corrupt your original file “/usr/share/zoneinfo/GMT”

I was puzzling weeks on it to find out that my original files were corrupted.
I got that hint from another thread out there.

Reply

32 jdros February 9, 2011

For Debian/Ubuntu, you have to edit

/etc/timezone

:

  • use
    dpkg-reconfigure tzdata

    , or

  • browse to
    /usr/share/zoneinfo/

    and locate your city in (relative) directory/file tree, i.e. Europe/Athens; put this exact string in

    /etc/timezone

    .

Reply

33 cmyster March 15, 2011

In Arch, simply edit /etc/rc.conf and modify TIMEZONE.
it sould be the relative path to the zoneinfo file in /usr/share/zoneinfo
for example to set your local time to New York:
> cd /usr/share/zoneinfo/
> find . -name New_York
./America/New_York

now edit rc.conf:
TIMEZONE=”America/New_York”

Reply

34 Pragnesh April 21, 2011

I want it to work for ‘UBUNTU’.
Please help.

Reply

35 Basil April 26, 2011

So after I use the /etc/localtime method sure if I type date the response from date is in the right timezone, but what about every running task, they are still using the old timezone. examples are crontab, mysqld, etc… obviously booting the system does ensure everything changes over, and cycling crontab for example fixes it, but is their a easy way to sync all without an outage.

Reply

36 Mohamed ibrahim May 30, 2011

Dear Vijay,
My Linux mechines are running under vmware server. My server time is changed every day. I reset my time every date with date -s command. But my windows mechines are running good. Time variation between linux and windows varied. Every day morning my clock shows 09:00 o clock but my server shows 09:50 or 10:00 or 10:03…. How do i set my linux box time constantly

Reply

37 frank June 10, 2011

can you help change time zone for linux suse

Reply

38 asdf August 18, 2011

suse: use yast

Reply

39 Rangalal Gamage August 26, 2011

It works for ubuntu/kubuntu also. Thanks a lot.

Reply

40 Chris September 1, 2011

Thanks! The ln method worked fine on FC14.
I noticed that some things (httpd) do not pick up the change until restarted.

Reply

41 krusha October 14, 2011

Hi,

I running shell script in Ec2-amazon web service.I dont want to change the time zone of server rather wanted to know with some command if I can get IST time.By default it shows UTC .I think if we pass some parameter with date command ,it should work. Please help me out .

Reply

42 pravinthali December 21, 2011

really a valuable information……………Thanks for that piece.

Reply

43 littleguy January 3, 2012

Setting timezone via /etc/localtime worked fine in CentOS 6!

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 15 + 9 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: