|This article provides an introduction to the concept of keeping time on computers in general, and describes how clocks are configured and managed in Parabola Gnu/Linux.|
|Network Time Protocol|
This article explains how to read and set the hardware clock (a.k.a. the Real Time Clock (RTC) or CMOS clock) and the system clock. For maintaining accurate system time, please see Network Time Protocol.
The hardware clock keeps values of year, month, day, hour, minute, and seconds. The hardware clock time value may either be in the localtime standard or the Coordinated Universal Time (UTC) standard (also known as GMT, though conceptually different). Localtime is dependent on your local time zone while UTC is global time and independent of time zone values. The hardware clock can only store time values and does not store information on whether localtime or UTC time is used, nor whether Daylight Saving Time (DST) is used.
All the most common operating systems can be told to use either UTC or localtime. By default, UNIX-like operating systems will generally set the hardware clock to UTC. When dual booting with other operating systems it is best to set all of them to use UTC to avoid clocks becoming incorrect when switching back and forth between each other.
In UNIX-like systems, the hardware clock can be queried and set with the hwclock command.
System also has a software clock (a.k.a. the system clock) that runs independent of the hardware clock. The system clock keeps track of the time, time zone, and whether or not your location uses DST. Parabola Gnu/Linux's daemon /etc/rc.d/hwclock (which makes use of the hwclock command) sets the system clock from the hardware clock at start (e.g. on boot), and sets the hardware clock from the system clock when stopped (e.g. on shutdown): users must include 'hwclock' in the DAEMONS list in /etc/rc.conf for this to happen automatically. As an alternative to using the hwclock daemon, users often use NTP to keep the system clock set to the proper time.
2 Time Standard
You can set the hardware clock time standard through the command line. You can check what you have set currently in a central configuration file by:
$ grep ^HARDWARECLOCK /etc/rc.conf
To immediately change the hardware clock time standard, you can set localtime by:
# hwclock --localtime
And to set it as UTC by:
# hwclock --utc
The time standard that the hardware clock uses will also need to be entered in your system configuration (rc.conf) so that the system clock will be correctly set at restart (if the hwclock script is used):
Your hardware clock and system clock time may need to be updated after this, read #Time Set.
3 Time Zone
Be sure that your time zone is set correctly in /etc/rc.conf, this not only is necessary for the localtime to be set correctly but also for other programs you may use. You can do this by:
$ grep ^TIMEZONE /etc/rc.conf
You can find the time zones listed in /usr/share/zoneinfo/ and then you will need to find a major city that exists to your time zone. If you live in a specialized time zone area these will be listed in sub-directories. An example configuration:
The new time zone will be taken into effect when you reboot. To change the timezone immediately you will need to link it or copy it to /etc/localtime:
# cp /usr/share/zoneinfo/America/Chicago /etc/localtime
When you set the hardware clock in the next step the new time zone will be used.
4 Time Set
The hardware clock can be set either directly or from the system clock. To check the current hardware clock time and system clock time respectively:
$ hwclock --show $ date
To set the hardware clock directly (in military time):
# hwclock --set --date "MM/DD/YYYY hh:mm:ss"
To set the system clock:
# date MMDDhhmmYYYY
The hardware clock can be set from the system clock and vice versa:
# hwclock --systohc # hwclock --hctosys
5 Time Skew
No clock is perfect. Every clock has a value that differs from 'real time' (the best representation of which being International Atomic Time). A quartz based electronic clock keeps imperfect time, but maintains a very consistent inaccuracy. This base 'inaccuracy' is known as 'time skew' or 'time drift'. Each time the hardware clock is set with hwclock (e.g. during shutdown), hwclock uses the new value, the old value and last time the hardware clock was set to calculate the drift in seconds per day. If the hwclock has not been set within the previous 24 hours; hwclock overwrites the previous drift with the new drift in the file /var/lib/hwclock/adjtime. The cron job script adjusts the hardware clock according to the recorded drift every hour. If you see that the hardware clock keeps losing or gaining time by large amounts, it is likely an invalid drift is recorded in /var/lib/hwclock/adjtime. This can happen if you have set the hardware clock time incorrectly. To fix this remove /var/lib/hwclock/adjtime, set the correct hardware clock and system clock time, and check if your time standard is correct.
The system clock is calculated by Linux as the number of seconds since midnight January 1st 1970 UTC. The initial value of the system clock is calculated from the hardware clock (after applying drift adjustment and converting to UTC) at power up and then runs independently of the hardware clock.Linux keeps track of the system clock by counting timer interrupts. The software clock is very accurate but like most clocks is not perfectly accurate and will drift as well. Though rarely, the system clock can lose accuracy if the kernel skips interrupts. System clocks can be kept on accurate time by using NTP. NTP will adjust the interrupt frequency and the number of ticks per second to decrease system clock drift. These values can also be adjusted by using the adjtimex application (from the AUR).