setting the system and hardware clock

created onAugust 13, 2025
last modified onAugust 14, 2025

TLDR? Head straight to putting it all together.

time formats UTC and local time; time zones

The world’s primary time standard is UTC, which is short for Coordinated Universal Time. UTC is defined as the time at the meridian with a longitude of 0°. It is the successor of GMT, Greenwich Median Time (Greenwich, UK, is located at the meridian with longitude 0°).

local time, the time at a certain location, is derived from UTC and the time zone of the location. Time zones are ’loosely defined’ by the longitude of the location. While the longitude of a location is a major factor to define its time zone, time zones tend to follow boundaries between countries and their subdivisions more than strictly following longitude, which makes sense for social, commercial or legal organisation.

UTC does not include the concept of DST, which is short for daylight savings time, which is used in many countries. I.e. in most countries in Europe, on the last Sunday in March, at 02:00 local time, the clock ist set forward to 03:00 local time. That is, the clock ’leaps’ one hour forward. On the last Sunday in October, at 03:00 local time, the clock is set backwards to 02:00 local time. The time zone of a location determines whether daylight savings apply.

hardware clock and system clock

PC compatibles have two clocks:

  • a hardware clock, which is an independent device on the machine’s motherboard, with its own battery. It operates continuously no matter whether the machine is running, powered off or even unplugged. This clock is also called RTC (real time clock), CMOS clock or (a bit outdated) BIOS clock.
  • a system clock, which is part of the operating system. When the machine boots, the system clock is initialized with the time of the hardware clock.

In GNU/Linux, the system clock is part of the kernel and is driven by a timer interrupt. It tracks the number of seconds since the unix epoch (January, 1st, 1970, 00:00) and is always in UTC. User space programs like act as a representation layer when displaying date and time to the user. While the most common use is to present date and time in the local time of the time zone in which the machine is located, date and time of other time zones can be calculated from the system clock’s UTC time.

timezone configuration

Usually, time is stored in the hardware clock on the machine’s mainboard using UTC.

The system clock is configured to show the date and time in the machine’s time zone. Date and time are read from the hardware clock and converted to the local time of the machine’s time zone. The time zone is configured in , which is a symlink to a zone info file in . Note that some zones do not have a subzone, i.e. the time zone ‘Navajo’ in Navajo Nation, which is located in Arizona, US, and does not use DST like the time zone US/Arizona.

I.e. for a machine located in Germany, the time zone Europe/Berlin is configured by creating a symlink to :

root@idoru:/$ ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime

displaying and setting hardware and system clock

displaying and setting the hardware clock with hwclock

is used to display and set the hardware clock time. displays the hardware clock’s current time.

displays the hardware clock’s time in localtime, even if the hardware clock is set to UTC. If the hardware clock is set to UTC and you want to display the time of the hardware clock in UTC, use or .

I find the latter rather confusing, but it is what it is.

To set hardware clock’s time is used, i.e.:

root@idoru:/$ hwclock --set --date "2025-08-14 20:09:45" --utc
The man page of hwclock states that the date argument must be in localtime, even if the hardware clock is set to UTC. I.e., if your localtime is two hours ahead, substract 2 hours from your current localtime.

Another strategy is to sync system clock to the hardware clock with (see below).

the file /etc/adjtime

If the hardware clock is set with the file is updated. If doesn’t exist, it is created.

The follwing is an example of an :

0.000000 1755203757 0.000000 1755203757 UTC
  • line 1: the first value is the clock drift rate in seconds per 24 hours, floating point decimal. the 2nd value is the number of seconds since the unix epoch (January 1st 1970, 00:00) since most recent hardware clock adjustment, integer decimal. the third value is for compatibility with and is always 0, floating point decimal
  • line 2: the number of seconds since the unix epoch (January 1st 1970, 00:00) since most recent hardware clock adjustment, integer decimal. It is 0 if there has been no calibration yet or if it is known that any of the previous calibrations was screwed up.
  • line 3: one value, which is either ‘UTC’ or ‘LOCAL’. This value tells whether the hardware clock is set to UTC or localtime.
The hardware clock itself does not hold any information whether it is set to UTC or localtime. If you want to know whether your hardware clock is set to UTC or localtime, check the third line of .

displaying and setting the system clock with date

With , the system’s clock time can be displayed and set. knows some predefined formats like ISO-8691 or RFC-3339, but you can also define the format arbitrarily from time and date components. The format can even span multiple lines. is your friend here. Following is an example:

rudolf@idoru:~$ date +"%Y-%m-%d %H:%M:%S" 2025-08-14 22:26:23
The resolution of date is down to nanoseconds (format string ‘%N’).

can convert between UTC and localtime:

rudolf@idoru:~$ date Fri Aug 15 01:04:50 PM CEST 2025 rudolf@idoru:~$ date --utc Fri Aug 15 11:04:55 AM UTC 2025

It can also convert between time zones, here is an example of displaying the current time in another time zone:

rudolf@idoru:~$ TZ='America/New_York' date Fri Aug 15 07:20:42 AM EDT 2025

The systems clock’s time and date can be set with , i.e. . Any format that date can be used to display date and timme can be used to set the date and time of the system clock.

syncing system clock and hardware clock with hwclock

sets the hardware clock from the system clock and updates . If doesn’t exist, it is created.

sets the system clock from the hardware clock.

hardware clock in UTC vs hardware clock in localtime

So why all that fuss with UTC and localtime? Why not just set the hardware clock to localtime and be done with it? In fact, Windows assumes the hardware clock to be in local time by default (but can be configured to use the hardware clock set to UTC).

If the machine is permanently located in a time zone without DST, this might be a viable option. But there are some scenarios in which a hardware clock set to local time can be a headache and UTC is the better option. Examples include:

  • time zones with DST. If the hardware clock is set to UTC, the current local time is automatically adapted to the daylight saving time (that is, the leap hours).
  • if one travels a lot between time zones. Nowadays machines usually do not have a static network configuration but get their configuration from a DHCP server in the network to which they connect. DHCP server can provide time zone information, enabling clients to automatically reconfigure themselves to a new time zone.
  • servers in a network that spans multiple time zones. Imagine comparing the logs of several servers, located in different time zones and sorting the events by the time these events occurred.

Of course, it doesn’t hurt to configure the hardware clock of a machine permanently located in a time zone without DST to UTC. Which is by convention the standard in GNU/Linux.

putting it all together to configure the clocks

set the system clock to the current local time and configure the time zone

  • set the system time with to localtime, i.e. .
  • configure the time zone with .

set the hardware clock to UTC (preferred) …

  • sync the system clock to the hardware clock with
  • check that the hardware clock is set correctly. With , you should get the correct current UTC time from the hardware clock.

or set the hardware clock to local time

  • sync the system clock to the hardware clock with
  • check that the hardware clock is set correctly. With , you should get the correct current local time from the hardware clock.
x