105 lines
4.9 KiB
Plaintext
105 lines
4.9 KiB
Plaintext
Setting up time and time zones
|
|
|
|
There are several things involved in getting time right under Linux:
|
|
|
|
- /usr/lib/zoneinfo contains files that define what time zone you
|
|
are in. If they are missing, no time zone calculations
|
|
are done, i.e. your internal clock is assumed to be on
|
|
local time rather than the Unix standard of GMT. The only
|
|
file that you absolutely need is /usr/lib/zoneinfo/localtime, but I
|
|
recommend also having /usr/lib/zoneinfo/posixrules. Posixrules
|
|
is typically a copy of or link to localtime. Localtime defines
|
|
your default zone. Posixrules is needed to interpret the TZ
|
|
variable, which is used if you want to specify a zone other than
|
|
the default.
|
|
|
|
- the "date" command can be used to set or display the date/time.
|
|
Note however that it does not set the hardware clock, so
|
|
next time you reboot, you'll be back to the old time.
|
|
I recommend that after changing the time with "date", you
|
|
use "clock -w" or "clock -u -w" to update the hardware clock
|
|
as well. (See below.)
|
|
|
|
- the "clock" command can be used to set or display the date/time
|
|
in the hardware (CMOS) clock. Typically your /etc/rc script
|
|
will contain
|
|
clock -s
|
|
which will cause the Unix date/time to be initialized from the
|
|
CMOS clock when you boot. If your CMOS clock is set to GMT
|
|
(which is what I recommend) the correct command is
|
|
clock -u -s
|
|
|
|
The binary time distribution should be untarred under /usr. It
|
|
contains lib/zoneinfo, bin/date, bin/clock, and doc/time.doc (this
|
|
file). Once you've installed these files, you'll want to do four
|
|
things:
|
|
|
|
1) set /usr/lib/zoneinfo/localtime and /usr/lib/zoneinfo/posixrules.
|
|
You should copy the file for your time zone. E.g. if you are in the
|
|
U.S. Eastern time zone, do
|
|
|
|
cd /usr/lib/zoneinfo
|
|
cp US/Eastern localtime
|
|
ln localtime posixrules
|
|
|
|
Localtime defines the local time zone. Posixrules defines the zone to
|
|
be used to interpret the TZ environment variable. Since it's far more
|
|
convenient simply to use the right time zone file, nothing more will
|
|
be said here about how the TZ variable is used. Unless you intend to
|
|
use TZ, you can ignore the next paragraph.
|
|
|
|
If you want exact POSIX behavior, posixrules should be a copy of or
|
|
link to one of the U.S. time zone files. (For non-U.S. daylight
|
|
rules, the TZ variable defines the daylight transition rules.)
|
|
However it may make more sense practically for it to be the same as
|
|
localtime, as shown in the instructions above.
|
|
|
|
2) Once you've set up localtime and posixrules, you can remove the
|
|
rest of the files in /usr/lib/zoneinfo, if you're sure you'll never
|
|
want to operate in any other time zone. Or you can keep just the few
|
|
time zones that you might need.
|
|
|
|
3) Put the correct "clock" command into /etc/rc. Which command to use
|
|
depends upon whether you want your hardware clock to keep local time
|
|
or GMT. I recommend using GMT, since that will allow daylight savings
|
|
transitions to be completely automatic. However the same clock is
|
|
used by DOS, and some people don't like the time in DOS being GMT. I
|
|
use Unix-compatible software under DOS. It uses the TZ environment
|
|
variable to do time zone conversion. Thus I prefer the clock being
|
|
GMT even under DOS. But some people may not like that. Anyway, if
|
|
your hardware clock is set to the local time, put the line
|
|
|
|
clock -s
|
|
|
|
in /etc/rc. This will set the Unix time from your hardware clock,
|
|
doing the necessary time conversion. If your hardware clock is set
|
|
to GMT, then you'll need the -u option:
|
|
|
|
clock -u -s
|
|
|
|
4) Now make sure that your hardware clock is set correctly. Try
|
|
"clock" with no arguments. It will print the current setting of the
|
|
hardware clock. Make sure it is right, and that it is either local or
|
|
GMT, as you decided. (If the hardware clock is supposed to be GMT,
|
|
you can use "clock -u". This will convert from GMT to local and
|
|
display it.) To set the clock, first use the "date" command to get
|
|
the date right in Unix. Then use "clock -w" to set the hardware
|
|
clock. Note that "clock -w" will set the hardware clock to the local
|
|
time, and "clock -u -w" will set it to GMT. Verify with "clock" that
|
|
the hardware clock is as you want it.
|
|
|
|
From now on, the time should be right. If your hardware clock loses
|
|
or gains time, you can update it at a future date by the same
|
|
procedure just described: first get the Unix time right using "date"
|
|
and then use "clock -w" or "clock -u -w" to set the hardware clock.
|
|
|
|
If your hardware clock is set using local time, make sure to reset it
|
|
when daylight time changes. If you're running Unix when daylight time
|
|
changes, the Unix time will adjust automatically. In that case, all
|
|
you need is "clock -w" to update the hardware clock. If you aren't
|
|
running Unix during the transition, then your time will be an hour off
|
|
the next time you boot. In that case, set the correct Unix time using
|
|
"date", and then use "clock -w" to update the hardware clock. If your
|
|
hardware clock is set using GMT time, none of this is necessary --
|
|
daylight time transitions will happen automatically.
|