This document explains how to
set your computer's clock from Linux, how to set your timezone, and
other stuff related to Linux and how it does its time-keeping.
Your computer has two
timepieces; a battery-backed one that is always running (the hardware,
BIOS, or CMOS clock), and another that is maintained by the operating
system currently running on your computer (the system clock). The
hardware clock is generally only used to set the system clock when your
operating system boots, and then from that point until you reboot or
turn off your system, the system clock is the one used to keep track of
On Linux systems, you have a
choice of keeping the hardware clock in UTC/GMT time or local time. The
preferred option is to keep it in UTC because then daylight savings can
be automatically accounted for. The only disadvantage
with keeping the hardware clock in UTC is that if you dual boot with an
operating system (such as DOS) that expects the hardware clock to be set
to local time, the time will always be wrong in that operating system.
Setting your timezone
The timezone under Linux is
set by a symbolic link from
to a file in the
directory that corresponds with what timezone you are in. For example,
since I'm in South Australia,
/etc/localtime is a symlink to
To set this link, type:
with something like
Have a look in the directories under
to see what timezones are available.
This assumes that
as it is under Red Hat Linux.
older systems, you'll find that
is used instead of
also the later section The time in some
applications is wrong.
Setting UTC or local time
When Linux boots, one of the
initialization scripts will run the
program to copy the current hardware clock time to the system clock.
will assume the hardware clock is set to local time unless it is run
switch. Rather than editing the startup script, under Red Hat Linux you
should edit the
file and change the
line to either UTC=true or UTC=false as appropriate.
Setting the system clock
To set the system clock
under Linux, use the
command. As an example, to set the current time and date to July 31,
(note that the time is given in 24 hour notation). If you wanted to
change the year as well, you could type
To set the seconds as well, type
To see what Linux thinks the current local time is, run
with no arguments.
Setting the hardware clock
To set the hardware clock,
my favourite way is to set the system clock first, and then set the
hardware clock to the current system clock by typing
/sbin/hwclock --systohc --utc
if you are keeping the hardware clock in UTC). To see what the hardware
clock is currently set to, run
with no arguments. If the hardware clock is in UTC and you want to see
the local equivalent, type
If some applications (such
display the correct time, but others don't, and you are running Red Hat
Linux 5.0 or 5.1, you most likely have run into a bug caused by a move
of the time zone information from
The fix is to create a symbolic link from
-s ../share/zoneinfo /usr/lib/zoneinfo.
sets whether the hardware clock is stored as UTC or local time.
to set your time zone.
to set the current system date/time.
/sbin/hwclock --systohc [--utc]
to set the hardware clock.
Other interesting notes
The Linux kernel always stores and
calculates time as the number of seconds since midnight of the 1st of
January 1970 UTC regardless of whether your hardware clock is stored as
UTC or not. Conversions to your local time are done at run-time. One
neat thing about this is that if someone is using your computer from a
different time zone, they can set the TZ environment variable and all
dates and times will appear correct for their time zone.
If the number of seconds since the
1st of January 1970 UTC is stored as an signed 32-bit integer (as it is
on your Linux/Intel system), your clock will stop working sometime on
the year 2038. Linux has no inherent Y2K problem, but it does have a
year 2038 problem. Hopefully we'll all be running Linux on 64-bit
systems by then. 64-bit integers will keep our clocks running quite well
until approximately the year 292271-million.
Other programs worth looking at
- get the current time from a remote machine; can be used to set the
but it's extremely accurate and you need a permanent 'net
runs continuously and accounts for things like network delay and
clock drift, but there's also a program (
included that just sets the current time like rdate does.
Home | Linux /etc file | Common Linux Commands Used on the Service Console | .vmx Parameters | How Convert Physical to Virtual | Deploy Terminal Server assigning C: to user and move profile on E: | How To: install Novell Netware 3.x on VMware | Linux, Clocks, and Time | Configuring a Cron Task | ISO image | Using VMKFSTOOLS intead of CP | NetBackup | VMTS.net is Alive | NetWorker | TSM