Changing the timezone of your Debian system

Posted by Steve on Sun 14 Aug 2005 at 16:33

Whilst changing the timezone of a machine once it has been installed is not a very common job it does seem to be something that many people struggle with.

When it comes to Debian systems the simple way to edit your timezone is to use the /usr/bin/tzselect command.

The tzselect command will prompt you for your region and then offer you a list of cities within that region.

For example selecting "Europe" from the available regions will present you with the following list of available cities to choose from:

Amsterdam Andorra Athens Belfast Belgrade Berlin Bratislava Brussels
Bucharest Budapest Chisinau Copenhagen Dublin Gibraltar Helsinki Istanbul
Kaliningrad Kiev Lisbon Ljubljana London Luxembourg Madrid Malta Mariehamn
Minsk Monaco Moscow Nicosia Oslo Paris Prague Riga Rome Samara San_Marino
Sarajevo Simferopol Skopje Sofia Stockholm Tallinn Tirane Tiraspol
Uzhgorod Vaduz Vatican Vienna Vilnius Warsaw Zagreb Zaporozhye Zurich

Once you've set your timezone you might wish to change the UTC setting, upon Debian machines you can find that in the file /etc/default/rcS. Although changing this will require a reboot.

(UTC refers to "Universal Time", the time upon your machine is calculated from that into the so-called "local time".)

If you find that your machine is not keeping the correct time properly you might wish to investigate using NTP to sync your clock.

 

 


Posted by kiwipete (219.88.xx.xx) on Mon 15 Aug 2005 at 08:54
Here in New Zealand we will change to daylight saving time at the start of October, i.e. the timezone will change from NZST to NZDT. Will I need to do anything manually to change the clock on my Debian box?

[ Parent | Reply to this comment ]

Posted by peterhoeg (193.163.xx.xx) on Mon 15 Aug 2005 at 09:25
Use NTP as outlined in the article.
  • aptitude install ntp-simple
  • edit /etc/default/ntp and change the server to pool.ntp.org
And there you go!

Alternatively, you can have one machine act as server, point that to pool.ntp.org and all the other servers/workstations to that local machine instead of pool.ntp.org.

[ Parent | Reply to this comment ]

Posted by Anonymous (62.157.xx.xx) on Mon 15 Aug 2005 at 10:27
UNIX has no problems with daylight savings. You may have probs if your machine is a double boot machine with this commercial system from redmond because then you have two systems which try to change the daylight savings in Bios. If you work with *nix only the best way is to let the Bios work with UTC. Then every *nix on a multi boot machine will do it right.

[ Parent | Reply to this comment ]

Posted by Anonymous (200.104.xx.xx) on Mon 15 Aug 2005 at 17:05
IIRC, if you have windows installed in your box, your BIOS clock has to be configured to local time, or else Windows will do lots of strange things (such as getting the wrong time).

[ Parent | Reply to this comment ]

Posted by fsateler (200.104.xx.xx) on Mon 15 Aug 2005 at 17:08
[ View Weblogs ]
Oops, I didn't realize I wasn't logged in..
--------
Felipe Sateler

[ Parent | Reply to this comment ]

Posted by Anonymous (84.137.xx.xx) on Fri 30 Sep 2005 at 07:28
getting the timezone like described here makes sense.
Changing 'utc' however might not make sense. I think
that changing /etc/timezone and /etc/localtime might
be a better way. But don't take my word for it.

[ Parent | Reply to this comment ]

Posted by Anonymous (216.254.xx.xx) on Thu 5 Jan 2006 at 22:25
From the debian docs...
it's tzconfig to CHANGE the timezone, and update your clock.

http://www.debian.org/doc/manuals/system-administrator/ch-sysadmi n-time.html#s-tzconfig

[ Parent | Reply to this comment ]

Posted by Anonymous (77.47.xx.xx) on Sat 16 Jul 2011 at 13:36
It's `sudo dpkg-reconfigure tzdata` - and no reboot is required...

[ Parent | Reply to this comment ]

Posted by linulin (212.119.xx.xx) on Mon 5 Jun 2006 at 18:45
Once you've set your timezone you might wish to change the UTC setting, upon Debian machines you can find that in the file /etc/default/rcS. Although changing this will require a reboot.

I think, 'hwclock --systohc --utc' command (in case UTC=yes) could be used instead of reboot.

...Bye..Dmitry.

[ Parent | Reply to this comment ]

Posted by Anonymous (24.68.xx.xx) on Fri 22 Jun 2007 at 08:23
This article is embarassing. This is not the way to change the timezone for your machine. The guy's link to tzconfig is correct.

tzselect will only change the timezone of your current shell. It is not even permanent (as will be explained when you run the command to completion).

I suggest this article be deleted so as not to spread misinformation.

This is how time works in Linux, and probably every other Unix.

Internally, the system keeps time in UTC. (French acronym for universal co-ordinated time, I believe). Same as GMT (Greenwich Mean Time). Look it up in Wikipedia.

/etc/localtime has the timezone that was selected when you installed the system.

It has stuff like:
1) offset in seconds from UTC
(there are a number of places that are 6.5 hours off UTC, and Nepal is +5 hours and 45 minutes! (though Nepal's capital Kathmandu is misspelled Katmandu))
2) whether daylight savings time applies to that timezone, and when daylight savings time applies
(as it can happen in different regions at different times, or not at all).

/etc/timezone is a file that has one line, the currently selected timezone. When you run tzconfig, it updates both /etc/localtime, and writes the timezone you selected in /etc/timezone. (At least on Debian versions Sarge and Etch...Woody didn't keep the timezone in /etc/timezone, but /etc/localtime was a soft-link to the timezone selected, so you could find out that way).

(All Linux distributions use /etc/localtime (well, all the ones I know about), but /etc/timezone is a Debian thing (probably Debian derivatives like Ubuntu and such as well). Redhat derived distributions like Fedora use /etc/sysconfig/clock to hold the currently selected timezone (plus whether your hardware clock is in UTC or not).

When an application needs the localtime, the system takes UTC (which is what the system is using internally), and applies the /etc/localtime information to it, to get your localtime.

If you have an environment variable called 'TZ' set to a different timezone, it will use that timezone instead of the one copied to /etc/localtime.

So, calling tzselect will only set your TZ environment for your current shell, and any programs started from that shell. The system will still use /etc/localtime for all other applications.

NTP will not do anything about daylight savings time. It is just a good source for the system to find out what UTC is. All daylight savings time info comes from /etc/localtime (or the timezone set in your TZ environment).

Perhaps it is needless to say, but you shouldn't muck with /etc/localtime and /etc/timezone yourself. Use tzconfig, as it will update both correctly, and possibly do some other stuff.

The rule of thumb for the UTC setting in /etc/default/rcS is that if your machine is not dual-booted, you can set UTC to yes. This simplifies things because UTC does not jump around based on daylight savings time, so when you boot after daylight savings time, the system doesn't have to guess whether the clock has been updated or not.

But if you dual boot with Windows, Windows will expect the hardware clock to be your localtime, so you should set UTC to no. Note: if you set UTC to yes, if you go into your BIOS, to change the clock, you will need to set it to UTC, as that is what the system will expect when booting. You'll probably notice soon enough that something is wrong.

Oh, and changing the UTC setting in /etc/default/rcS does not require a reboot. True, the clock will not be set until you shutdown properly and the system writes the UTC to the clock, but nothing requires you to do that after modifying that value.

[ Parent | Reply to this comment ]

Posted by pssbrasil (201.82.xx.xx) on Tue 2 Oct 2007 at 17:23
Thank you for your time explaining the correct way to setup the timezone.

[ Parent | Reply to this comment ]

Posted by Anonymous (66.92.xx.xx) on Tue 6 Nov 2007 at 05:22
tzconfig is obsolete. The correct way on a modern (lenny) Debian box is to run:

dpkg-reconfigure tzdata

[ Parent | Reply to this comment ]

Posted by Anonymous (65.57.xx.xx) on Thu 13 Dec 2007 at 20:32
Thank you! Thank you! Thank you!

Is this updated in the Lenny manual?

wt

[ Parent | Reply to this comment ]

Posted by Anonymous (203.8.xx.xx) on Thu 19 Mar 2009 at 01:59
Hi.

Thanks for providing the modern command.

Is there anyway of passing the desired timezone from the command line instead of through the interactive user interface???

[ Parent | Reply to this comment ]

Posted by Anonymous (86.166.xx.xx) on Fri 11 Sep 2009 at 23:54
Thanks, this one command is all you need!

[ Parent | Reply to this comment ]

Posted by Anonymous (213.172.xx.xx) on Tue 12 Apr 2011 at 18:01
Can you run this command non-interactively? I need to change the timezone from a shell script, without a user selecting the timezone.

[ Parent | Reply to this comment ]

Posted by Anonymous (88.198.xx.xx) on Sun 13 Nov 2011 at 16:11
Yes, you can. To set the system timezone non-interactively, execute:
echo 'Etc/UTC' > /etc/timezone
dpkg-reconfigure --frontend noninteractive tzdata

[ Parent | Reply to this comment ]

Posted by Anonymous (82.181.xx.xx) on Sun 23 Mar 2008 at 13:29
Thanks for this information!

[ Parent | Reply to this comment ]

Posted by Anonymous (210.55.xx.xx) on Mon 9 Mar 2009 at 19:56
Really glad I read the whole article before I started doing anything...

FTW, for Lenny, tzconfig is depreciated, use dpkg-reconfigure tzdata instead.

[ Parent | Reply to this comment ]

Posted by Anonymous (2001:0xx:0xx:0xxx:0xxx:0xxx:xx) on Tue 17 Mar 2009 at 10:09
...and if you want the new timezone to show up in your logs, etc., don't forget to restart all daemons that log - including sysklogd ;-)

[ Parent | Reply to this comment ]

Posted by Anonymous (66.195.xx.xx) on Wed 15 May 2013 at 22:52
Not very helpful. From the man page: "Note that tzselect will not actually change the timezone for you. Use 'dpkg-reconfigure tzdata' to achieve this."

[ Parent | Reply to this comment ]

Posted by Anonymous (90.193.xx.xx) on Wed 15 May 2013 at 22:52

Bear in mind this article was posted in 2005...

[ Parent | Reply to this comment ]

Posted by Anonymous (108.243.xx.xx) on Sat 17 May 2014 at 15:06
dpkg-reconfigure tzdata worked just fine for me on debian 7.4 in May 2014.

[ Parent | Reply to this comment ]

Posted by Anonymous (86.24.xx.xx) on Wed 13 Aug 2014 at 15:22
I relocated from Perth Western Australia back to Bournemouth UK.
I dual-boot (only occasionally) into W8.
I have reformatted and installed Mint17 and have been struggling ever since to get my clock correct.
My bios is set to Local British Summer Time (GMT+1)
I do dpkg-reconfigure tzdata Europe, London, and it is 8 hours out, using Mint KDE. I wouldn't worry about it, just set my bios for GMT-8hrs but for the Windaz boot.
I use Mythtv and timing is critical for recordings. The EPG data is so screwed, I can't record anything, it's 8 hours out. Why does my machine still think it's in Australia when I installed Mint 17 KDE in Bournemouth?
Any help gratefully acceted.

Tony.

vidtek99@gmail.com

[ Parent | Reply to this comment ]

Sign In

Username:

Password:

[Register|Advanced]

 

Flattr

 

Current Poll

What do you use for configuration management?








( 331 votes ~ 1 comments )