If you just got your new CentOS server.

After a while you notice that timestamps in your logfiles are shifted with few hours. So what could be wrong?
Actually is really simple – most probably your timezone is not correct. To check run “date” from command line, this will show what is the time for your server.
Then you find that the timezone is not correct?!

How do you set the correct one?

Unfortunately, this is not an easy thing to figure out. Official documentation states that you can use system-config-date, but it has a bunch of dependencies (when I ran yum install system-config-date on one of my servers it asked to install 84 packages).

So is there an alternative way to do it?

All timezone files are located in /usr/share/zoneinfo. To select the appropriate named timezone for your location. For my location, Montreal, Canada, I actually have to select: America/Montreal. For you it could be different so make note of the appropriate folder and file for your timezone.

The active timezone used on your system is in the /etc/localtime file.

The default will vary depending on your server host and it depends on the value that was provided during installation.
We simply need to replace this file with the file we selected in the previous step.
Even I say replace, actually is recommended to create a link to the pertinent file rather than actually replacing the file.

Here are the steps to follow:

First, backup the existing localtime file (it is always good practice to make backups of original config files).

mv /etc/localtime /etc/localtime.bak

Next, create the link:

ln -s /usr/share/zoneinfo/ /etc/localtime

Test your change.
Run “date” from the command line, and ensure that the appropriate time, date, and timezone are reported.

Comments

One Response to “Change timezone in CentOS – command line”

  1. Daniel on August 15th, 2012 9:36 pm

    Tks man, you save my day

Leave a Reply