Difference between revisions of "Time"

From ArchWiki
Jump to: navigation, search
(Notes: This information has no use here.)
m (Add link to french page)
Line 1: Line 1:

Revision as of 12:11, 29 July 2012

Summary help replacing me
This article provides an introduction to the concept of keeping time on computers in general, and describes how clocks are configured and managed in Arch Linux.
Network Time Protocol

In an operating system the time (clock) is determined by four parts: Time value, Time standard, Time Zone, and DST (Daylight Saving Time if applicable). This article explains what they are and how to read/set them. To maintain accurate system time on a network see Network Time Protocol.

Hardware clock and system clock

A computer has two clocks that need to be considered the "Hardware clock" and the "System/software clock":


System clock (a.k.a. the software clock) keeps track of: Time, Time Zone, and DST if applicable. It is calculated by the Linux kernel as the number of seconds since midnight January 1st 1970 UTC. The initial value of the system clock is calculated from the hardware clock, dependent on the value of the HARDWARECLOCK variable defined in /etc/rc.conf. After boot-up has completed the system clock runs independently of the hardware clock. The Linux kernel keeps track of the system clock by counting timer interrupts.

Read clock


# hwclock --show
$ date

Set clock

To set the system clock directly:

# date MMDDhhmmYYYY

To set the hardware clock directly (the argument must be in local time, even if you keep your hardware clock in UTC.):

# hwclock --set --date="YYYY-MM-DD hh:mm:ss"

The hardware clock can be set from the system clock and vice versa:

# hwclock --systohc
# hwclock --hctosys

hwclock daemon

Standard behavior of most operating systems is:

  • Set the system clock from the hardware clock on boot
  • Keep accurate time of the system clock with an NTP daemon
  • Set the hardware clock from the system clock on shutdown. (On Arch Linux, the hardware clock is NOT set from system clock on shutdown. Although, it is adjusted for systematic drift with the --adjust flag).

Arch Linux initscripts use hwclock to set the system clocks on boot, if hwclock is in the daemons list in /etc/rc.conf hwclock will also sync time on shutdown. Using the hwclock daemon is not recommended if running the NTP daemon as the NTP daemon adjusts the hardware clock, which may lead to hwclock --adjust miscalculations.

Time standard


The standard used by hardware clock (CMOS clock, the time that appears in BIOS) is defined by operating system. By default, Windows uses localtime, Mac OS uses UTC, and UNIX-like operating systems vary. An OS that uses UTC standard, generally, will consider CMOS (hardware clock) time a UTC time (GMT, Greenwitch time) and make an adjustment to it while setting System time on boot according to your time zone.



$ grep ^HARDWARECLOCK /etc/rc.conf

The hardware clock can be queried and set with the hwclock command. To immediately change the hardware clock time standard to localtime use:

# hwclock --localtime

And to set it to UTC use:

# hwclock --utc

The time standard that the hardware clock uses will also need to be entered in your Arch Linux system configuration (rc.conf) so that the system clock will be correctly set on boot:




During kernel startup, at the point when the RTC driver is loaded, the system clock may be set from the hardware clock. Whether this occurs or not depends on the hardware platform, the version of the kernel and kernel build options. If this does occur, at this point in the boot sequence, the hardware clock time is assumed to be UTC and the value of /proc/sys/class/rtcN/hctosys (N=0,1,2,..) will be set to 1. Later during execution of /etc/rc.sysinit, the system clock is set again from the hardware clock dependent on the value of HARDWARECLOCK. Hence, having the hardware clock using localtime may cause some unexpected behavior during the boot sequence; e.g system time going backwards which is always a bad idea.

UTC in Windows

Add the DWORD value:


with hexadecimal value 1 to the registry (through regedit). Windows XP and Windows Vista SP1 have support for setting the time standard as UTC and can be activated in the same way however there is a bug after resuming from the suspend/hibernation state that resets the clock to localtime. For these operating systems it is recommended to use localtime.


Common problems

A common source of problems is that different programs that interact with the real time clock do not agree whether or not it should be in UTC or localtime. This tends to manifest itself in the time being consistently off by the same number of hours as your timezone differs from UTC.


Once this is configured correctly, make sure that both system time and the real time clock are up-to-date, before the next reboot.

Time Zone

Be sure that your time zone is set correctly in /etc/rc.conf. This is necessary not only 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 time zone immediately, you will need to link it to /etc/localtime:


When you set the hardware clock the new time zone will be used; you can check your system's hardware clock within your BIOS.

Time Skew

Every clock has a value that differs from real time (the best representation of which being International Atomic Time), no clock is perfect. A quartz based electronic clock keeps imperfect time, but maintains a consistent inaccuracy. This base 'inaccuracy' is known as 'time skew' or 'time drift'.

When the hardware clock is set with hwclock, a new drift value is calculated in seconds per day. The drift value is calculated by using the difference between the new value set and the hardware clock value just before the set, taking into account the value of the previous drift value and the last time the hardware clock was set. The new drift value and the time when the clock was set is written to the file /etc/adjtime overwriting the previous values. The hardware clock can be adjusted for drift when the command hwclock --adjust is run; this occurs by default on shutdown if the hwclock daemon is enabled.

Note: If the hwclock has been set again less than 24 hours after a previous set, the drift is not recalculated as hwclock considers the elapsed time period too short to accurately calculate the drift. It may be worth occasionally to stay in Linux so it gets calculated


