Changing Time zone in Linux

By | February 25, 2013

Here is how you change the timezone in Red Hat Linux:

Type date to see what the current time zone is set to.  By default it should be EST.

Changing the time zone may take some thinking.  Ideally the customer should tell you the time zone in this format:

GMT + 2 – Pretoria/Harare

This will be enough to go off of in most situations.  If you are unsure what it equates to, Google it!

We will be replacing the timezone file found in /etc/localtime.  This file outputs the date/time when you use the date command.  To find the various time zones available to you, browse to:

cd /usr/share/zoneinfo/

Once here you can use ls -al (or ll) to list the time zone files.  These contain the information Linux needs to use the appropriate time.  Using the example above, we know that GMT + 2 – Pretoria/Harare is time located in Africa (found by using the Google box).  In this case I will browse to the sub folder:

/usr/share/zoneinfo/Africa

Once here, if you ls -al (or ll) you will get a list of potential time zones in Africa.  Checking the list, there isn’t any Pretoria listed, however Harare is.  Now all I have to do is copy the file and replace the existing /etc/localtime file:

cp /usr/share/zoneinfo/Africa/Harare /etc/localtime

Press “Y” for the overwrite and then type date to confirm the time zone matches up.  After that you are good to go.  Note:  By default, PHP will use the system time unless otherwise specified in the configuration file (/etc/php.ini).