I'm setting the timezone to GMT+6 on my Linux machine by copying the zoneinfo file to /etc/localtime, but the date command is still showing the time as UTCtime-6. Can any one explain to me this behavior?

I'm assuming the date command should display UTCtime+6 time. Here are steps I'm following:

date
Wed Jan 22 17:29:01 IST 2014

date -u
Wed Jan 22 11:59:01 UTC 2014

cp /usr/share/zoneinfo/Etc/GMT+6 /etc/localtime

date
Wed Jan 22 05:59:21 GMT+6 2014

date -u
Wed Jan 22 11:59:01 UTC 2014

closed as off-topic by slm, Anthon, Zelda, rahmu, manatwork Jan 23 '14 at 9:47

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question has been posted on multiple sites. Cross-posting is strongly discouraged; see the help center and community FAQ for more information." – slm, Anthon, Zelda, rahmu, manatwork

  • Has TZ environment variable been set (does echo $TZ produce something but an empty line)? Also it might be a better idea to create a symlink to /etc/localtime instead of copying the actual file (that way you'll be safe, in case zoneinfo data ever changes which it most likely never will). – Sami Laine Jan 23 '14 at 4:53
  • What's the distro? Different distros handle this differently! – slm Jan 23 '14 at 5:29
  • @slm:I'm using ubuntu 12.04 – Rahul Dhobi Jan 23 '14 at 5:41
  • You likely did not know this policy but you're not suppose to cross post the same Q's on the different SE sites. stackoverflow.com/questions/21282367/timezone-setting-in-linux – slm Jan 23 '14 at 7:43
  • Also cross posted to Super User: Timezone setting in Linux – Peter Mortensen Nov 13 '14 at 9:21
up vote 236 down vote accepted

Take a look at this blog post titled: How To: 2 Methods To Change TimeZone in Linux.

Red Hat distros

If you're using a distribution such as Red Hat then your approach of copying the file would be mostly acceptable.

NOTE: If you're looking for a distro-agnostic solution, this also works on Debian, though there are simpler approaches below if you only need to be concerned with Debian machines.

$ ls /usr/share/zoneinfo/
Africa/      CET          Etc/         Hongkong     Kwajalein    Pacific/     ROK          zone.tab
America/     Chile/       Europe/      HST          Libya        Poland       Singapore    Zulu
Antarctica/  CST6CDT      GB           Iceland      MET          Portugal     Turkey       
Arctic/      Cuba         GB-Eire      Indian/      Mexico/      posix/       UCT          
Asia/        EET          GMT          Iran         MST          posixrules   Universal    
Atlantic/    Egypt        GMT0         iso3166.tab  MST7MDT      PRC          US/          
Australia/   Eire         GMT-0        Israel       Navajo       PST8PDT      UTC          
Brazil/      EST          GMT+0        Jamaica      NZ           right/       WET          
Canada/      EST5EDT      Greenwich    Japan        NZ-CHAT      ROC          W-SU         

I would recommend linking to it rather than copying however.

$ sudo unlink /etc/localtime 
$ sudo ln -s /usr/share/zoneinfo/Etc/GMT+6 /etc/localtime

Now date shows the different timezone:

$ date -u
Thu Jan 23 05:40:31 UTC 2014

$ date 
Wed Jan 22 23:40:38 GMT+6 2014

Ubuntu/Debian Distros

To change the timezone on either of these distros you can use this command:

$ sudo dpkg-reconfigure tzdata

    ss #1

$ sudo dpkg-reconfigure tzdata

Current default time zone: 'Etc/GMT-6'
Local time is now:      Thu Jan 23 11:52:16 GMT-6 2014.
Universal Time is now:  Thu Jan 23 05:52:16 UTC 2014.

Now when we check it out:

$ date -u
Thu Jan 23 05:53:32 UTC 2014

$ date 
Thu Jan 23 11:53:33 GMT-6 2014

NOTE: There's also this option in Ubuntu 14.04 and higher with a single command (source: Ask Ubuntu - setting timezone from terminal):

$ sudo timedatectl set-timezone Etc/GMT-6

On the use of "Etc/GMT+6"

excerpt from @MattJohnson's answer on SO

Zones like Etc/GMT+6 are intentionally reversed for backwards compatibility with POSIX standards. See the comments in this file.

You should almost never need to use these zones. Instead you should be using a fully named time zone like America/New_York or Europe/London or whatever is appropriate for your location. Refer to the list here.

  • 1
    refer answer of this question here stackoverflow.com/questions/21282367/timezone-setting-in-linux – Rahul Dhobi Jan 23 '14 at 7:22
  • @user3184706 - you've kind of made a mess here. Your Q here was how to change the timezone, which I answered. The bit about using GMT.. timezone or not that the SO A provided is accurate, but I neglected to include that here, since you weren't really asking about that, though I thought. I can either add that bit to this A or you can copy/paste that info here as your own A. – slm Jan 23 '14 at 7:47
  • @user3184706 - to try and clean this up I included Matt's A in mine to make it complete. – slm Jan 23 '14 at 7:56
  • Thanks man, this "sudo dpkg-reconfigure tzdata" works in my Debian!!! – JRichardsz Sep 8 '16 at 17:04
  • 1
    Note though that if you're in a container, with Ubuntu you have to install the package tzdata or else the files in /usr/share/zoneinfo won't exist. – Elliott Slaughter Sep 5 at 23:30

This is how I do it in Ubuntu. Just replace Asia/Tokyo with your own timezone.

echo 'Asia/Tokyo' | sudo tee /etc/timezone

sudo dpkg-reconfigure -f noninteractive tzdata

There is a bug in tzdata: certain values get normalized by dpkg-reconfigure:

echo 'US/Central' >/etc/timezone
dpkg-reconfigure -f noninteractive tzdata
# Current default time zone: 'America/Chicago'

echo 'US/Eastern' >/etc/timezone
apt-get install --reinstall tzdata
# Current default time zone: 'America/New_York'
  • This also works, but in Debian/Ubuntu, slm's answer is probably easier and less risky (no chance of typos) – Andreas Hartmann Nov 18 '17 at 19:05

tzselect command is made to do what you want.

  • And to condense that into a single line that sets the TZ variable to your local timezone - e.g., for America/Los_Angeles - export TZ=`printf "2\n49\n21\n1\n" | tzselect 2>&1 | tail -1` . You can put this line in your .profile, as tzselect` helpfully suggests, were you to run it at the prompt. – sameers Apr 23 '15 at 16:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.