33

Here is the output of my date command:

[root@r1304 ~]# date
Wed Apr 18 15:43:28 GST 2012

I want to change the default system timezone to Asia/Dubai. I've followed a tutorial and did this:

ln -sf /usr/share/zoneinfo/Asia/Dubai /etc/localtime

But with no effect. Seems that this is done differently in CentOS 6. How do I change the timezone?

peterh
  • 4,914
  • 13
  • 29
  • 44
Temnovit
  • 1,107
  • 6
  • 19
  • 27

5 Answers5

45

It looks like that CentOS 6.2 doesn't have any hwclock line in it /etc/rc.sysinit, so changing /etc/sysconfig/clock will not work.

Try tzselect or use ln -s /usr/share/zoneinfo/xxxx /etc/localtime

frmbelz
  • 109
  • 5
caojun
  • 466
  • 4
  • 2
  • 5
    Thanks, that worked for me. My solution was `rm /etc/localtime && ln -s /usr/share/zoneinfo/America/New_York /etc/localtime`. – Banjer Feb 03 '13 at 21:00
  • What's better to use for this - `ln` or `cp`? – XåpplI'-I0llwlg'I - Sep 09 '14 at 12:28
  • In this case, using a symlink is probably better than copying the file – JDS Oct 21 '14 at 15:13
  • 2
    Do this, but also make sure to update the `/etc/sysconfig/clock` with the correct timezone as updates can and will change localtime back to what is in the clock. – Justin Mar 19 '15 at 16:21
  • `ln -s` is better than `cp` because if the tzdata package updates the zone file for your region you will see the changes without having to copy it again. – David Purdue Nov 10 '15 at 02:50
9

First use tzselect to find out which is your timezone. The final output of tzselect will be something like:

Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
America/New_York

The very last line is the name of your zoneinfo file.

Now create a symlink from /etc/localtime to the correct zoneinfo file, e.g.:

ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime 

The -f flag is needed to overwrite the existing /etc/localtime.

Note: running tzselect won't touch anything on your system, it will just output some text. The "or" in the answer by caojun is misleading. You must use tzselect AND ln. From the tzselect manpage: "[tzselect] outputs the resulting timezone description to standard output".

Luca Gibelli
  • 2,611
  • 1
  • 21
  • 29
4

Edit the file /etc/sysconfig/clock to suit your needs.

pkhamre
  • 5,900
  • 3
  • 15
  • 27
  • 1
    That's not a complete solution. You need to set the timezone offset. – ewwhite Nov 25 '12 at 00:47
  • 5
    although this is not a complete answer, this step is quite essential. without updating sysconfig/clock (something we did not do when changing timezones)... running certain yum updates / installs (unsure which ones), will cause the timezone to revert to the one listed in sysconfig/clock... regardless of what /etc/localtime was replaced with. so yea... make sure to update sysconfig/clock to make your timezone change stick. – anonymous-one Mar 19 '13 at 13:07
  • 1
    Yum update can cause a disaster in case /etc/localtime and /etc/sysconfig/clock point to two different timezones. Updating mysql for instance can cause a nice time shift in all the dates. – elbuild Oct 19 '14 at 17:40
2

One should restart rsyslogd after changing the timezone so that the new timezone is reflected in the logs.

Do this with: service rsyslog restart

Ed Greenberg
  • 166
  • 1
  • 5
1

Simple tutorial, try this..

[root@dlp ~]# vi /etc/sysconfig/clock

# change to your location
ZONE="Asia/Tokyo"

[root@dlp ~]# source /etc/sysconfig/clock # reload
# copy your timezone file under the "/usr/share/zoneinfo" like follows
[root@dlp ~]# cp -p /usr/share/zoneinfo
rails_id
  • 119
  • 3
  • this worked for me, other options didn't – Bokw Sep 18 '13 at 07:20
  • 1
    If these instructions work at all, it'd be good to explain _why_ ... I see no reason why sourcing `/etc/sysconfig/clock` would have any effect on the subsequent `cp` program (or indeed, on any subsequent program) – offby1 Aug 25 '14 at 22:37