Fix the timezone data on CentOSFix the timezone data on CentOS

Posted May 17th, 2012 in Linux/Unix/BSD

I've had an annoying issue on some CentOS 5 virtual machines where I set the timezone to Pacific/Auckland and it doesn't work. This post shows the error and then how to rebuild/reinstall the timezone data.

Changing the timezone

I wanted to change the timezone from Eastern time to New Zealand time. To highlight how it didn't work the example below shows: the date command, showing the current date, time and timezone; attempting to set the date; and then showing the current date and time again.

$ date
Wed May 16 23:23:23 EDT 2012
$ ln -sf /usr/share/zoneinfo/Pacific/Auckland /etc/localtime
$ date
Wed May 16 23:26:23 EDT 2012

No, it didn't seem to make any difference. The timezone is still EDT.

The fix

It's very easy, simply run "yum reinstall tzdata -y" as root or using sudo. The -y flag at the end simply means you don't need to type y and <enter> when it's time to say yes, you do want to do the reinstall.

$ yum reinstall tzdata -y
... lots of output ...
$ ln -sf /usr/share/zoneinfo/Pacific/Auckland /etc/localtime
$ date
Thu May 17 15:30:42 NZST 2012

Excellent, now the timezone has changed.

Related posts:

Comments

blog comments powered by Disqus