6

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?

1
  • Can you provide the output of strace -v date?
    – ott--
    Oct 5, 2013 at 20:01

4 Answers 4

2

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
2
  • I think you found the problem. Here is the output of zdump -v /etc/localtime: /etc/localtime -9223372036854775808 = NULL /etc/localtime -9223372036854689408 = NULL /etc/localtime 9223372036854689407 = NULL /etc/localtime 9223372036854775807 = NULL
    – smusumeche
    Oct 7, 2013 at 15:02
  • 1
    updating tzdata via yum solved my problem.
    – smusumeche
    Oct 7, 2013 at 15:06
4

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 contains ZONE="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
2
  • 1
    I tried all of this, yet the date is still output in UTC. I noticed in my /etc/sysconfig/clock file, there is a variable called UTC set to true. I tried setting that to false (without rebooting) but it didn't change anything. What does your entire clock file look like?
    – smusumeche
    Oct 5, 2013 at 19:47
  • That's all that's in my clock file.
    – ewwhite
    Oct 5, 2013 at 20:01
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
3
  • I checked all of these locations and TZ is not set anywhere. I ran echo $TZ from the command line and got a blank response:
    – smusumeche
    Oct 5, 2013 at 19:48
  • 1
    A blank response doesn't help you in this case, since even a TZ variable set to an empty string makes date report back in UTC, as pointed out in my answer. Instead, check the output of env or set for the occurrence of TZ. Also check that your /usr/share/zoneinfo/US/Central is a valid existing file. Oct 5, 2013 at 19:51
  • My zone file appears valid: file -L /usr/share/zoneinfo/US/Central /usr/share/zoneinfo/US/Central: timezone data. I also ran printenv and the TZ variable is not set.
    – smusumeche
    Oct 7, 2013 at 14:42
2

I had the exact same issue and updating tzdata fixed it for me:

yum update tzdata

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .