Posted by: kezhong | March 8, 2010

Change Timezone on CentOS 5.4

Check the current timezone

# cat /etc/sysconfig/clock
ZONE=”America/Toronto”
UTC=true
ARC=false

There are two ways to change the timezone on CentOS.

1. Set the timezone by running system-config-date command

Before running the system-config-date tool, I created a file named “timestamp” as timestamp.

# date > timestamp

Type the system-config-date command at the command line to start the time and date properties tool.

# system-config-date

I selected “America/Vancouver” and press “OK” to exit.

Use the following command to find which configuration files had been changed.

# find /etc –newer timestamp
/etc/sysconfig/clock
/etc/localtime

From the above output, I know /etc/sysconfig/clock and /etc/localtime had been changed. Open the file /etc/sysconfig/clock, I found the “ZONE” had been changed. And I found the /etc/localtime had the same size with the file “/usr/share/zoneinfo/America/Vancouver”.

2. Set the timezone using /etc/sysconfig/clock and /etc/localtime configuration files

Since I know which files affect the timezone, I can modify manually. Use “vi” to modify the file /etc/sysconfig/clock, and change the “Vancouver” back to “Toronto”. Then copy “/usr/share/zoneinfo/America/Toronto” to /etc/localtime or use symbolic link command as below.

# ln -sf /usr/share/zoneinfo/America/Toronto /etc/localtime

Write the current System Time to the Hardware Clock

After changed the timezone, don’t forget to check the date and time using the date command, and then write the current System Time to the Hardware Clock.

# hwclock —systohc

Display date and time according to timezone

You can use TZ environment variable to display date and time according to your timezone. For example, I can display the local time of Los Angeles as below.

$ export TZ=America/Los_Angeles
$ date

There are two clocks on Linux system, which one is the Hardware Clock and the other one is the System Time. The Hardware Clock keeps running after the system shutdowns. When a Linux system boots, the script /etc/rc.d/rc.sysinit will run the /sbin/hwclock program to set the System Time from the Hardware Clock. When you want to set the Hardware Clock, you should use the date command to set the System Time first, and then set the Hardware Clock to the current System Time with the command /sbin/hwclock –systohc.


Responses

  1. Hello, U helpme ! Thanks so much !

  2. Thanks! it was useful.

  3. i have updated mine

    however it shows the time using date as

    17:42:43 CST 2011

    when that is the wrong time, it is only 11:39am right now in Costa rica….

  4. Funcionou corretamento no CentOS 5.5

    Alterei meu timezone para America/Fortaleza sem maiores dificuldades!

    Parabéns!

  5. […] http://chrisjean.com/2009/03/03/change-timezone-in-centos/http://www.electrictoolbox.com/centos-fix-timezone-data/http://www.cyberciti.biz/faq/howto-linux-unix-change-setup-timezone-tz-variable/http://www.thegeekstuff.com/2010/09/change-timezone-in-linux/http://kiteplans.info/2012/03/06/centos-timezone-change-uk-gmt0/https://kezhong.wordpress.com/2010/03/08/change-timezone-on-centos-5-4/ […]

  6. […] a quick search I found that CentOS uses /etc/localtime and /etc/sysconfig/clock (see for example kezhong.wordpress.com/2010/03/08/change-timezone-on-centos-5-4). Setting the timezone again might […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: