CentOS Ignoring Timezone and showing UTC
I've set my server's timezone to Central:
/etc/localtime -> /usr/share/zoneinfo/US/Central
After rebooting, when I run the date command, the time is still listed in UTC.
[root@dev etc]# date
Sat Oct 5 16:14:28 UTC 2013
How can I get it to display in the local timezone?
Solution 1:
You could check if there is something wrong with this file: /etc/localtime
Using for example:
zdump -v /usr/share/zoneinfo/US/Central or zdump -v /etc/localtime
In my case the information for this year looks like this:
/usr/share/zoneinfo/US/Central Sun Mar 10 07:59:59 2013 UTC = Sun Mar 10 01:59:59 2013 CST isdst=0 gmtoff=-21600
/usr/share/zoneinfo/US/Central Sun Mar 10 08:00:00 2013 UTC = Sun Mar 10 03:00:00 2013 CDT isdst=1 gmtoff=-18000
/usr/share/zoneinfo/US/Central Sun Nov 3 06:59:59 2013 UTC = Sun Nov 3 01:59:59 2013 CDT isdst=1 gmtoff=-18000
/usr/share/zoneinfo/US/Central Sun Nov 3 07:00:00 2013 UTC = Sun Nov 3 01:00:00 2013 CST isdst=0 gmtoff=-21600
Solution 2:
Timekeeping tips for your CentOS system.
- Set the timezone offset with something like:
ln -fs /usr/share/zoneinfo/America/Chicago /etc/localtime
- Check the contents of
/etc/sysconfig/clock
- Mine only containsZONE="America/Chicago"
- Turn on
ntp
. There's no excuse not to have it running. - If this is a physical system, you may want to set your hardware clock in your bios or set it from your OS with
hwclock -w
These changes take effect immediately, such that your date command should output:
# date
Sat Oct 5 11:38:49 CDT 2013
Solution 3:
Also make sure that the environment variable TZ
is unset, as it overrides what is configured by /etc/localtime
.
Even an innocent export TZ=
makes date (and other utilities) default to outputting UTC.
Check /etc/environment
, /etc/profile
, /etc/bash.bashrc
, ~/.profile
, ~/.bashrc
, your Desktop Environment configuration and other commonly sourced configuration files for instances of setting and exporting TZ and remove them.
Edit:
Also check that your /usr/share/zoneinfo/US/Central
is a valid existing file:
$ file -L /usr/share/zoneinfo/US/Central /usr/share/zoneinfo/US/Central: timezone data, version 2, 6 gmt time flags, 6 std time flags, no leap seconds, 235 transition times, 6 abbreviation chars
Solution 4:
I had the exact same issue and updating tzdata fixed it for me:
yum update tzdata