Changing the timezone, date, and time
Setting your time zone
In /etc the file, localtime, is a link to or copy of a file containing information about your time zone. Zone information files are usually in /usr/share/zoneinfo but this depends on your distribution. So if your localtime file points to a zone info file that is not your time zone you can change it by browsing the directories in /usr/share/zoneinfo to find your country, then find your city or a city in the same time zone and link localtime to it.
Some applications may use the configuration file /etc/sysconfig/clock to determine the current time zone so it's a good idea to set the ZONE entry (e.g. "America/Los_Angeles").
$ ln -sf /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
Changing the date and time
Changing the date and time requires two steps. First, Linux's date and time must be changed and then the new time has to be written to the hardware clock.
The date command can be used for both viewing and changing the date and time.
To change the time use date followed by the month, day, hour, minute, and year all numeric and no spaces. So, to set the date and time to November 2nd, 2003 12:57
The hardware clock can be updated in UTC (coordinated universal time) or your local time. It is standard practice to update it in UTC.
To update it to your local time leave off the --utc or add --localtime and leave off the --utc.
The date and time can be changed directly to the hardware clock and then used to update the system clock.
Using NTP (Network Time Protocol)
NTP will connect to a server to get the atomic time. It can be downloaded from www.ntp.org/downloads.html
To get started with NTP simply download it, install it, use the ntpdate command followed by a public time server, and update your hardware clock.
A public time server can be found at http://support.ntp.org/bin/view/Servers/WebHome
$ ntpdate "server DNS name or IP address"|
4 Nov 22:31:28 ntpdate: step time server 22.214.171.124 offset 22317290.440932 sec
$ hwclock --systohc
To keep your time accurate you can create a cron job that executes:
(the -w option is the same as --systohc)
ntpdate "server name" && hwclock -w
To stay independent of a particiluar server you can use 0.pool.ntp.org (0, 1, or 2) for the server name. This domain uses DNS round robin to choose different time servers every so often. This keeps certain nameservers from having high loads. The only disadvantage is the increased potential of updating time from a nameserver who is in the pool but has an incorrect time settings.
These are volunteer public servers so be polite, do not constantly access the public servers, use only public servers (not private), and if you have multiple machines, set up a ntp server and have your other machines retrieve the time from your local server. Check http://www.eecis.udel.edu/~mills/ntp/servers.html for detailed rules.
rdate is a different package that is used in the same way that ntpdate is. It doesn't support running your own time server like NTP does, but can access the same time servers.
rdate "server name" && hwclock -w
NIST/Department of Commerce Official US Time - What time is it?
A Walk Through Time - Interesting information about the history of keeping track of time.
Thanks Michael Barnes for updated link for time servers.
Thanks Austin Duncan for the information about pool.ntp.org.
Thanks Evan Davey for the information about the ZONE entry.
Corrections, comments, questions e-mail email@example.com
Top of Page