17 Clock: Date and Time


There are two clocks in a computer: the system clock and the hardware clock. The system clock is maintained by the running operating system (e.g., GNU/Linux). It is also said to be maintained by the kernel. The hardware clock is part of the actual hardware of the computer and is usually battery backed up. The current status of the clock can be found from the timedatectl command from systemd, systemd:


The output might be something like:

               Local time: Mon 2022-07-04 14:33:47 AEST
           Universal time: Mon 2022-07-04 04:33:47 UTC
                 RTC time: Mon 2022-07-04 04:33:47
                Time zone: Australia/Sydney (AEST, +1000)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

If the system clock is not being synchronised then that can be turned on with:

timedatectl set-ntp yes

To set the timezone:

$ sudo timedatectl set-timezone Australia/Canberra

The date command will also show the current time from the system clock:

## Wed Jul 10 03:44:19 PM AEST 2024

Meanwhile, the hwclock command talks to the hardware clock:

$ sudo hwclock
2021-03-23 07:42:20.426656+11:00

To set the system clock:

$ sudo date -s "13 Jun 2021 10:10:00"

Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0