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.
[ Parent | Reply to this comment ]
- aptitude install ntp-simple
- edit /etc/default/ntp and change the server to pool.ntp.org
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 ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
--------
Felipe Sateler
[ Parent | Reply to this comment ]
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 ]
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 ]
I think, 'hwclock --systohc --utc' command (in case UTC=yes) could be used instead of reboot.
...Bye..Dmitry.
[ Parent | Reply to this comment ]
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 ]
[ Parent | Reply to this comment ]
dpkg-reconfigure tzdata
[ Parent | Reply to this comment ]
Is this updated in the Lenny manual?
wt
[ Parent | Reply to this comment ]
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 ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
FTW, for Lenny, tzconfig is depreciated, use dpkg-reconfigure tzdata instead.
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]