System time

The system time, backed by the system clock, Article description::is used in Unix systems to keep track of time. It can be set by an onboard hardware clock or by an external time server.

Software clock vs Hardware clock
The system clock, provided by the kernel, is implemented as a simple count of the number of ticks that have transpired since the 1 January 1970 00:00:00 UTC. This is called Unix time.

The hardware clock (also known as real-time clock or RTC) is typically a component on the mainboard. It runs independent of the state of the operating system all the time, also when the computer is shutdown.

UTC time vs localtime
tl;dr: Use UTC to avoid various troubles; avoid localtime unless you have a special reason. To dual boot with Windows, you need an additional step from Windows. See the Arch Linux Wiki article System Time, section UTC in Windows.

The time for hardware clock can be modified to represent two standards: localtime or UTC time. The localtime is the real time of the time zone including DST. Preferred is UTC time because the system time gets computed by adding the time zone difference and DST. So daylight saving changes get automatically applied and changing the time zone are possible without changing the hardware clock. Exceptions can be made when using a dual-boot system; this is when the other operating system does not support or is not configured for an UTC hardware clock (by default, Windows uses localtime).

Time zone
In order to keep time properly, select the proper time zone so the system knows where it is located.

OpenRC
See Timezone (AMD64 Handbook).

systemd
systemd comes with the command to manage the time zone:

To check the current zone:

To list available zones:

To change the time zone, e.g. for Germany:

LC_TIME
This environment variable defines formatting of dates and times. For more details see The GNU C Library

Hardware clock
Usually you need a hardware clock. Then the following kernel options must be activated:

At runtime, to check the current hardware clock time:

To set the hardware clock to the current system clock:

Syncing the hardware clock and system time
Typically the hardware clock is used to setup the system clock on boot. This can be done by the kernel itself or by a boot service (init script). Also on shutdown the kernel or a service can write the software clock to the hardware clock. This aids the system in having the correct time on boot.

In-kernel method
On a sufficiently modern kernel (3.9 or newer), Linux can be configured to handle setting the system time automatically. To do so, enable the Set system time from RTC on startup and resume ( CONFIG_RTC_HCTOSYS ) and Set the RTC time based on NTP synchronization ( CONFIG_RTC_SYSTOHC ) kernel options:

The Set the RTC time based on NTP synchronization kernel option is currently supported by chrony, NTP and OpenNTPD since version 5.9p1.

To check if the hardware time is updated, install and run:

The 64 bit of the reported number should be unset (0). More information in man pages (search '11 minute mode').

OpenRC
When using OpenRC the init script can set the system clock on boot and sync system time to the hardware clock on shutdown. The service is enabled by default and should be disabled in favor of the above mentioned in-kernel method. The script should not be run when using the kernel's real time clock.

If however there is a need for using the OpenRC, set both clock_hctosys and clock_systohc to  in. By default the service is configured for UTC time standard. To change to localtime add.

Restart the service and have the hardware clock init script run on system boot:

systemd
systemd can be used to set the system clock on boot. Use to manage the hardware clock:

To check the current hardware clock time:

To set the hardware clock to the current system clock (UTC time standard):

To set the hardware clock to the current system clock (localtime time standard):

Time server
See the page NTP to set the clock using time servers.

Setting clock manually
To "set" (or to adjust) the clock means to set the system clock.

Usually the system clock is set on boot by reading the hardware clock. To check the current software clock time from the command line, do:

To manually set the system clock from the command line, e.g. to 12:34, May 6, 2016, use the command:

Or to advance the clock by two minutes, do

systemd
If you use systemd, run  instead of ; to check the current time,

To set the system clock:

Dual booting with Windows
To dual boot with Windows and to use UTC, you need an additional step from Windows. See the Arch Wiki article System Time, section UTC in Windows.

External resources

 * https://lifehacker.com/5742148/fix-windows-clock-issues-when-dual-booting-with-os-x - Dual booting with MS Windows, set RealTimeIsUniversal. Also tested with Windows 10.
 * http://tldp.org/HOWTO/Clock-2.html - The Clock Mini-HOWTO.