How To: 2 Methods To Change TimeZone in Linux

by Ramesh Natarajan on September 29, 2010

Question: When I installed the Linux OS, I forgot to set the proper timezone. How do I change the timezone on my Linux distribution. I use CentOS (Red Hat Linux). But, can you please explain me how to do this on all Linux distributions with some clear examples.

Answer: Use one of the following methods to change the timezone on your Linux system. One of these methods should work for you depending on the Linux distribution you are using.

Method 1: Change TimeZone Using /etc/localtime File

For this example, assume that your current timezone is UTC as shown below. You would like to change this to Pacific Time.

# date
Mon Sep 17 22:59:24 UTC 2010

On some distributions (for example, CentOS), the timezone is controlled by /etc/localtime file.

Delete the current localtime file under /etc/ directory

# cd /etc
# rm localtime

All US timezones are located under under the /usr/share/zoneinfo/US directory as shown below.

# ls /usr/share/zoneinfo/US/
Alaska          Arizona         Eastern         Hawaii          Michigan        Pacific
Aleutian        Central         East-Indiana    Indiana-Starke  Mountain        Samoa

Note: For other country timezones, browse the /usr/share/zoneinfo directory

Link the Pacific file from the above US directory to the /etc/localtime directory as shown below.

# cd /etc
# ln -s /usr/share/zoneinfo/US/Pacific localtime

Now the timezone on your Linux system is changed to US Pacific time as shown below.

# date
Mon Sep 17 23:10:14 PDT 2010

Method 2: Change TimeZone Using /etc/timezone File

On some distributions (for example, Ubuntu), the timezone is controlled by /etc/timezone file.

For example, your current timezone might be US Eastern time (New York) as shown below.

# cat /etc/timezone
America/New_York

To change this to US Pacific time (Los Angeles), modify the /etc/timezone file as shown below.

# vim /etc/timezone
America/Los_Angeles

Also, set the timezone from the command line using the TZ variable.

# export TZ=America/Los_Angeles

Linux Sysadmin Course Linux provides several powerful administrative tools and utilities which will help you to manage your systems effectively. If you don’t know what these tools are and how to use them, you could be spending lot of time trying to perform even the basic administrative tasks. The focus of this course is to help you understand system administration tools, which will help you to become an effective Linux system administrator.
Get the Linux Sysadmin Course Now!

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

{ 13 comments… read them below or add one }

1 beparas September 29, 2010 at 12:30 am

This is very useful information.
Thanks.

2 Dharmit Shah September 29, 2010 at 2:18 am

Great stuff. Really handy!

3 charon September 29, 2010 at 5:52 am

Method 1 is bad. Sometimes after updating system this settings reset.

4 James September 29, 2010 at 10:56 am

RHEL/CentOS actually copies files from /usr/share/zoneinfo to /etc/localtime based on /etc/sysconfig/clock settings. Symlinks will be blown away everytime after tzdata update

5 chmurli October 1, 2010 at 1:59 pm

archlinux has one file to configure many cool stuff (timezone, deamons etc) – /etc/rc.conf
I think there is similar file in slackware and BSD.

6 Anonymous April 12, 2011 at 6:10 am

Great article .

Regards,
Ajay Rai

7 Anonymous October 30, 2011 at 9:37 pm

No work on SL6 (another RHEL clone) either. Sorry!

8 chandan June 7, 2012 at 2:50 pm

I tried all these but its not working. These steps works fine on my machine but wondering why its not working on the production machine where it should work.

Any idea or more methods of changing the timezone?

9 Sai November 8, 2012 at 5:43 am

@chandan :
What exactly is the issue you are facing ?

10 fabriberloco February 17, 2013 at 2:45 pm

It works, thanks a lot!

11 Mostafa July 4, 2013 at 2:06 pm

thanks a lot it works

12 Pratik August 29, 2013 at 7:11 pm

Try tzselect command….

13 Ben October 22, 2013 at 10:31 am

I found this on another website, but this method worked perfectly:

Open the terminal. This method will open an ASCII menu that will allow you to choose your timezone. Enter the following command based on the Linux distribution you are using:

Ubuntu: dpkg-reconfigure tzdata
Redhat: redhat-config-date
CentOS/Fedora: system-config-date
FreeBSD/Slackware: tzselect

Regards!

Leave a Comment

Previous post:

Next post: